我有一个登录表单,在接受主表单登录后运行,并且这种登录形式是隐藏的,但是当我关闭主表单时,程序仍在运行。 我使用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 :(得分:-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();
}