为什么主窗体关闭了,子窗体还不关闭还有  。我在VS2005上调试程序。。有2个窗体。一个登陆框,一个主窗体。进入主窗体后登陆框 this.hide()为什么我点击关闭主窗体时,VS还是处于不可编辑状态?他的意思是 登陆框  还没关闭。。我还要手动结束调试才行。。用哪个方法可以 在进入主窗体后 彻底的关闭登陆框?
exit  close  都是  把所有的都关了。主窗体都进不去了。
唯有hide可以。。但是,貌似是给隐藏了 不是关闭

解决方案 »

  1.   

    有2个窗体。一个登陆框,一个主窗体。进入主窗体后登陆框 this.hide()为什么我点击关闭主窗体时,VS还是处于不可编辑状态?你关闭主窗体,但是你登陆窗体还没关闭,只是他是隐藏的,解决办法,你在主窗体关闭事件里面把整个应用程序都关闭
    private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                App.ExitApplication();
            }
      

  2.   

    在主窗体关闭的时候 ,调用Application.Exit();
      

  3.   

    两种方法:
    1.在主窗体关闭的时候直接调用Application.Exit();2.先打开主窗体
    在program.cs中 
    Application.Run(new FrmMain());
    然后在主窗体的登陆事件中调用打开登陆窗体private void FrmMain_Load(object sender, EventArgs e)
            {
                #region //加载
                FrmLogin log = new FrmLogin();
                if (log.ShowDialog() == DialogResult.OK)
                {
                    //UserID = log.UserID;
                    //UserName = log.UserName;
                    //UserPassword = log.UserPassword;
                }
                else
                {
                    return;
                }
                #endregion
            }最后在登陆窗体的登陆确定按钮中private void btnLogin_Click(object sender, EventArgs e)
            {
                if (!string.IsNullOrEmpty(txtName.Text))
                {
                    if (Common.SingletonConnection.CheckLogin("select * from r_expertinfo where userName='" + txtName.Text + "' and password='" + txtPwd.Text + "'"))
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("用户名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtName.Focus();
                }
            }