我写了一个程序,有一个登录框和一个主程序框,现在登录框我验证用户名密码之后
MessageBox.Show("登录成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
dbca.Close();//数据库链接
this.Close();
front.Show();我的本意是关闭当前的登录框,然后显示主程序,可是这样执行之后,登录框是关了,可程序也退出了,请问我应该怎么办,使得第2个窗体正常工作,第一个窗体也能正常卸载??
MessageBox.Show("登录成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
dbca.Close();//数据库链接
this.Close();
front.Show();我的本意是关闭当前的登录框,然后显示主程序,可是这样执行之后,登录框是关了,可程序也退出了,请问我应该怎么办,使得第2个窗体正常工作,第一个窗体也能正常卸载??
可以把Application.Run设为主程序
在主程序的Load事件中调用登录框
static void Main()
{
Application.Run(new Form_GuestRegister());
} private bool Login()
{//登录
//true 退出
//true 登陆成功
//false 用户名密码错误
frmLG = new Form_Login();
int intDone = 0;
bool bolDone = false; intDone = frmLGShowDialog();
if (intDone == 0)
{
bolDone = true;
this.Close();
}
if (intDone == 1)
{
bolDone = true;
datTime = new DateTime(0);
stpE_Id.Text = "ID " + strE_Id;
stpE_Name.Text = "服务生 " + strE_Name;
}
if (intDone == 2)
{
MessageBox.Show("用户名密码输入有误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
if (intDone == 3)
{
MessageBox.Show("查询出错", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
return bolDone;
} private void Form_GuestRegister_Load(object sender, System.EventArgs e)
{
while(!Login());
}
frm.Show();
Application.Run();登陆窗口:
MessageBox.Show("登录成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
dbca.Close();//数据库链接
this.Close();front.Show();//主窗口主窗口:在主窗口关闭事件中private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
能再细一点吗?我是C#新手,不好意思,不太明白那些代码放到什么地方
private void opennewwin() 這里定義一個方法
{
this.close();
front frm=new front(); front為你想要打開的哪個窗口
frm.Show();
}
最後在你驗證密碼ok後打開新窗口時哪里寫
//線程
ThreadStart ts = new ThreadStart(opennewwin);//調用上面的哪個方法,不用加()
Thread tt = new Thread(ts);
tt.Start();