tags:

views:

32

answers:

2

In C sharp win forms, not using MDI, m creating multiple forms i wish to hide the previous form while loading a new form on a button's click i write the following code to achieve the purpose but the previous form still remains visible, kindly help!! here's the code...

private void btnEmployee_Click(object sender, EventArgs e)
{
    Form f3 = new EmployeeLogIn();
    f3.Show();
    Form id = new Login();
    id.Hide();
}
A: 

Your code will only continue when the form is loaded, so when the f3.Show() statement is finished.

Consider showing the f3 form in a new thread.

Gerrie Schenck
+1  A: 

You're hiding a newly-created form. You need to get the reference to the previous form by either passing it into the current form, or using a static property.

EDIT: actually I think this is what you wanted to do:

private void btnEmployee_Click(object sender, EventArgs e)
{
    Form f3 = new EmployeeLogIn();
    f3.Show();

    this.Hide();
}
Codesleuth