我的主窗体是登录窗体,程序的入口在主窗体frmMain()在这个窗体中(login窗体),
我没有登录直接按了login窗体右上角的关闭按钮或单击控制图标下的关闭,就回到了frmMain()窗体,怎样才能让按了login窗体右上角的关闭按钮就退出所有程序。

解决方案 »

  1.   

    用window.shodiadlg一类的方式弹出窗口,然后根据返回值做处理
      

  2.   

    我明白你的意思了 取消你主窗体frmMain()上面的关闭按钮这不就行啦
      

  3.   

    没看懂你意思。像QQ那样,登陆窗体点击‘登陆’后,登陆窗体关闭,打开新的窗体。        private void btnLog_Click(object sender, EventArgs e)
            {
               
                //登陆判断
                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;
                }           
            }
      

  4.   

    Application.Exit(); 在关闭的事件里面写
      

  5.   

    其实可以修改Program.CS中的代码。
    在Application.Start(new Form1());(详细代码忘了,有可能是其他,但同一个意思),前在加一句:
    Application.Start(new frmLogin());
    我一直就这么干的
      

  6.   

    如果你出现这些问题,说明你的登录方案不理想,你应该用ApplicationContext来实现
      

  7.   

    在login窗体的form_closing事件里面写Application.Exit();
      

  8.   

    楼主,现在又2中解决方案:
    1.利用窗体的closed事件,写Application.Exit();
    2.利用窗体的DialgoResult 在 “登录窗体”和Program.cs两个文件里写代码,如果感兴趣,我再细说