-1

I have a login form that runs after the main form login is accepted, and this form of login is hidden, but when I close the main form, the program is still running. i used this.close() but after login main form is closed!

I want to leave the application when the main form is closed

 UserBLL x = new UserBLL();

            if (x.loginAcount(TextBox1.Text, TextBox2.Text) == true)
            {
                MessageBox.Show("You are successfully logged in", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
                MainForm frm = new MainForm();
                frm.ShowDialog();


            }

            else
            {
                MessageBox.Show("Username or password is incorrect", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }

1 Answers1

-1

if you want to exit application then add this line

 Application.Exit();

to detect if main form is closed, you need to use FormClosingEventHandler and after detecting that main form is closed, then exit application

  this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.yourMainForm_FormClosing);


private void yourMainForm_FormClosing(object sender, FormClosingEventArgs e)
{
  //here you can exit from application 
  Application.Exit();
}
Saif
  • 2,611
  • 3
  • 17
  • 37