Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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.
Posted
Updated 4-Oct-13 3:13am
v2

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

and code

C#
this.Hide();

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


As Madhu told. Thanks Madhu

FYI.. :)
 
Share this answer
 
Write Login.hide() before Main.show()
 
Share this answer
 
You have to close the login form when you show the main form. Check this.
Winforms: Close your form during Load event[^]
 
Share this answer
 
XML
Thanks Madhu for replying but i am still facing the same. I have inserted below code.

<pre lang="c#">
else
            {
                Login login = new Login();
                login.Hide();

                Main main = new Main();
                main.Show();
            }
</pre>

anything else we can do this to resolve this..??
 
Share this answer
 
Comments
Madhu Nair 7-Oct-13 1:31am    
Ashok, please mark the solution as answered as it might help someone else also
Thanks thatraja but your solution is also insufficient .. :(
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900