2017-10-21 81 views
-1

我有一个登录表单,主窗体登录被接受后运行,并且这种登录形式是隐藏的,但是当我关闭主窗体时,程序仍然是运行。 我使用this.close()但登录后主窗体关闭!当主窗体关闭时,我想离开应用程序

我要离开这个应用程序时,主窗体关闭

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); 

      } 
+0

你想完全退出应用程序吗? – Saif

+0

@saif是的,我想在主窗体关闭时离开应用程序 –

回答

-1

,如果你想退出应用程序,然后加入这一行

Application.Exit(); 

来检测,如果主要形式是关闭,则需要使用FormClosingEventHandler,并在检测到主窗体关闭后退出应用程序

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(); 
} 
相关问题