Wont work because the code control will halt on form2.ShowDialog();
.
You will have to show form2 in a non-modal fashion:
Form2 form2 = new Form2();
form2.Show();
this.Close();
Or I guess you could fake it by hiding the form:
Form2 form2 = new Form2();
this.Visible = false;
form2.Show();
this.Visible = true;
Try both versions to see which is better in your situation. Calling ShowDialog();
will show the form as Modal causing all user mouse/keyboard input to be limited to form2 until you close it.
Edit: The Form2 must be declared as a member variable, it will go out of scope if it is decalred in the button event.
Form2 form2 = new Form2();
private void btnOK_Click(object sender, EventArgs e)
{
this.Visible = false;
form2.Show();
this.Visible = true;
}