我的主窗体是登录窗体,程序的入口在主窗体frmMain()在这个窗体中(login窗体),
我没有登录直接按了login窗体右上角的关闭按钮或单击控制图标下的关闭,就回到了frmMain()窗体,怎样才能让按了login窗体右上角的关闭按钮就退出所有程序。
我没有登录直接按了login窗体右上角的关闭按钮或单击控制图标下的关闭,就回到了frmMain()窗体,怎样才能让按了login窗体右上角的关闭按钮就退出所有程序。
{
//登陆判断
string userName = this.texName.Text;
string userpwd = this.texPwd.Text;
string userCard=this.texCombo.Text;
try
{
int id = Convert.ToInt32(userName);
string getpwd = Employee.SelectByID(id).Password;
if (userName == getpwd && userCard != "--请选择--")
{
//登陆正确
LoginInf.userName = userName;
LoginInf.userPwd = userpwd;
LoginInf.userCad = userCard; //关闭登陆框转到首页
this.Hide();
new Home().ShowDialog();
this.Close();
}
else
{
//登陆失败
MessageBox.Show("登陆失败");
}
}
catch {
MessageBox.Show("登陆失败!!!");
return;
}
}
在Application.Start(new Form1());(详细代码忘了,有可能是其他,但同一个意思),前在加一句:
Application.Start(new frmLogin());
我一直就这么干的
1.利用窗体的closed事件,写Application.Exit();
2.利用窗体的DialgoResult 在 “登录窗体”和Program.cs两个文件里写代码,如果感兴趣,我再细说