登录表单不是自动关闭。 [英] Login form not closing auotomatically.

查看:98
本文介绍了登录表单不是自动关闭。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio 2010中开发一个应用程序,因为这已经创建了一个登录表单,它从SQL Server 2008获取凭据并登录。一切正常,直到这里。我希望当用户使用正确的凭据登录时,应该关闭登录表单,并且应该打开MDI父表单。为此我在MDI加载事件中写下面的代码。



 private void Main_Load(object sender,EventArgs e)
{

登录login = new登录();
login.MdiParent = this;
login.Show();

}





及以下登录表格中的代码登录butten



  private   void  LogBtn_Click( object  sender,EventArgs e)
{
// 在此登录逻辑。

int count = ds.Tables [ 0 ].Rows.Count;
if (count == 0
{
MessageBox。显示( 无效的密码或用户名 注意,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
else
{
Main main = new Main();
main.Show();
}





当我运行此应用程序并在登录表单上输入正确的凭据登录表单预计将关闭但它赢了关闭。当我手动关闭登录表单时,MDI父表和登录表单都会关闭。



请帮我解决这个问题。



先谢谢。

解决方案

大家好。得到解决方案,但删除MDI父母后,使用简单的表格。



和代码



  .Hide(); 

Main main = new Main();
main.Show();





正如Madhu所说。谢谢Madhu



FYI ..:)


在Main.show()之前写一下Login.hide()


显示主窗体时必须关闭登录表单。检查一下。

Winforms:关闭表单在加载事件期间 [ ^ ]

Hi, I am developing an application in Visual Studio 2010 for this is have created Login form which takes credentials from SQL server 2008 and log in. Everything goes right till here. I wish that when user login with correct credentials login form should be closed and MDI parent form should be open. For this i wrote below code in MDI load event.

private void Main_Load(object sender, EventArgs e)
{

login login = new Login();
login.MdiParent = this;
login.Show();

}



and below code in Login forms Login butten

private void LogBtn_Click(object sender, EventArgs e)
        {
          //Login logic here.

            int count = ds.Tables[0].Rows.Count;
            if (count == 0)
            {
                MessageBox.Show("Invalid password or Username", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                Main main = new Main();
                main.Show();
            }



When I run this Application and enter the correct credentials on login form Login form expected to close but it won't close. When I close the Login form manually both MDI parent and Login form gets closed.

Please help me to resolve this issue.

Thanks in advance.

解决方案

Hi All. got solution but after removing MDI parent and use simple form.

and code

this.Hide();

Main main = new Main();
main.Show();



As Madhu told. Thanks Madhu

FYI.. :)


Write Login.hide() before Main.show()


You have to close the login form when you show the main form. Check this.
Winforms: Close your form during Load event[^]


这篇关于登录表单不是自动关闭。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆