Opening a New Form and Closing the Current Form in C#
When navigating through an application, it may be necessary to open a new form and close the current one. This can be achieved through a series of steps:
Opening a New Form
Closing the Current Form
Focusing on the New Form
Example Implementation
The following code snippet demonstrates how to open a new form (Form2) and close the current form (Form1) in C# using the steps described above:
private void OnButton1Click(object sender, EventArgs e) { this.Hide(); var form2 = new Form2(); form2.Closed += (s, args) => this.Close(); form2.Show(false); form2.Activate(); }
The above is the detailed content of How to Open a New Form and Close the Current Form in C#?. For more information, please follow other related articles on the PHP Chinese website!