Click here to Skip to main content
15,923,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guy. Please can u help me to solve this Problem. I have Form1(With Buttom Login) and i have a Form2(With Buttom logout).
1. after that the User enter his Name,zhe correct Passwort and click on the Login Buttom, the Form2 st opened and Form1 get hide. Later when the User is loging out is Form2 Unenable and Form1 appear again and the neww User kann sign in and use Form2 again.

But my Problem is that i don't find out how to use the same Form2. everithing i try open me a new Instance of Form2.
Form1 Login
C#
private void btnLogin_Click(object sender, EventArgs e)
{
    try
    {
        UserApplication user = new UserApplication(userName);
        user.Show();

    } catch(Exception ex){
        MessageBox.Show(ex.Message);
    }
}

Form2 Logout
C#
private void btnLogout_Click(object sender, EventArgs e)
 {
     try
     {
         Login in = new Login();
         in.Visible = true;

     }
    catch(Exception ex)
    {
         MessageBox.Show(ex.Message);
     }
 }

i don't find a possibility to solve this Problem. i get always a new instance. do you have some idea?
Posted

Yes. Stop doing that.
Don't use Show - use ShowDialog:
C#
private void btnLogin_Click(object sender, EventArgs e)
    {
    try
        {
        UserApplication user = new UserApplication(userName);
        Hide();
        user.ShowDialog();
        Show();
        }
    catch (Exception ex)
        {
        MessageBox.Show(ex.Message);
        }
    }
And
C#
private void btnLogout_Click(object sender, EventArgs e)
    {
    Close();
    }
Will fix it for you.
 
Share this answer
 
Hi friend,
You can use the Settings.settings file to save you data of Form2 present in properties folder.I think this will help you.
Good luck
 
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