I'm using winforms now. I have the main form "form1" and I have a button that opens form2. When I open form2 I would like for form1 to disappear. When the user click the x button on form2 I would like for it to close and go back to form1. I wouldn't like to use modal windows.
private void button1_Click(object sender, EventArgs e) {
var frm = new Form2();
frm.Location = this.Location;
frm.StartPosition = FormStartPosition.Manual;
frm.FormClosing += delegate { this.Show(); };
frm.Show();
this.Hide();
}
In order not to change Form's Properties, simply use the ShowDialog()
method in Form1.cs
code to open Form2
. That will deactivate Form1
:
void OpenSecondForm()
{
Form form2 = new Form();
form2.ShowDialog();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With