Sir, I need your help once again. I have a main form and login form. The scenario here is if the user will close the login form it should be the the whole application will close or exit. How will i do this Sir?
Actually Sir I'm developing a system now for my thesis. I am a graduating I.T student.
Thank you very much!
vergel aranasPosted Jul 8, 2012, 3:09 PM
VulpesPosted Jul 8, 2012, 2:41 PM
vergel aranasPosted Jul 8, 2012, 2:28 PM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace VetirenaryInformationSystem
{
public partial class PasswordForm : Form
{
private string conn = "SERVER = localhost; DATABASE = veterinary_db; UID = root; PASSWORD = ;";
public PasswordForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void PasswordForm_Load(object sender, EventArgs e)
{
TXTusername.CharacterCasing = CharacterCasing.Upper;
TXTpassword.CharacterCasing = CharacterCasing.Upper;
}
private void BTNLOGIN_Click(object sender, EventArgs e)
{
if (loging(TXTusername.Text, TXTpassword.Text) == true)
{
MessageBox.Show("Successfully login","Comfirm message",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show("Username and password not match. Please try again!","Error message",MessageBoxButtons.OK,MessageBoxIcon.Error);
TXTpassword.Text = "";
TXTusername.Text = "";
}
}
public bool loging(string username, string password)
{
string login = "SELECT username, userPass from userrecord WHERE username = '" + TXTusername.Text + "' AND userPass ='" + TXTpassword.Text + "'";
MySqlConnection connect = new MySqlConnection(conn);
MySqlCommand cmd = new MySqlCommand("SELECT username, userPass from userrecord WHERE username = '" + username + "' AND userPass ='" + password + "'");
cmd.Connection = connect;
connect.Open();
MySqlDataReader read = cmd.ExecuteReader();
if (read.Read() != false)
{
if(read.IsDBNull(0) == true)
{
cmd.Connection.Close();
read.Dispose();
cmd.Dispose();
return true;
}
else
{
cmd.Connection.Close();
read.Dispose();
cmd.Dispose();
return true;
}
}
else
{
return false;
}
}
private void PasswordForm_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
}
}
vergel aranasPosted Jul 8, 2012, 2:12 PM
VulpesPosted Jul 8, 2012, 2:06 PM
So, if you add a handler for that (go to the form's Properties Box and double click on the FormClosed event) and insert Application.Exit() within the handler, then it should do what you want.
vergel aranasPosted Jul 8, 2012, 2:02 PM
Thank you Sir.
VulpesPosted Jul 8, 2012, 1:55 PM