Now I use winforms. I have the main form "form1" and I have a button that opens form2. When I open form 2, I would like form 1 to disappear. When the user presses the x button on form2, I would like it to close and return to form1. I would not want 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(); }
To not change the properties of the form , simply use the ShowDialog() method in Form1.cs to open Form2 . This will disable Form1 :
ShowDialog()
Form1.cs
Form2
Form1
void OpenSecondForm() { Form form2 = new Form(); form2.ShowDialog(); }