WinForms Navigation Guide
In a WinForm application, navigation between forms can be achieved through the following methods:
- To navigate between forms, you can use the Show method by creating a new form object and then calling its Show method to display the new form. For example:
Form2 form2 = new Form2();
form2.Show();
- By using the ShowDialog method: similar to the Show method, but the ShowDialog method will display the new form as a modal dialog, meaning users cannot interact with other forms until the current form is closed. For example:
Form2 form2 = new Form2();
form2.ShowDialog();
- By using the Application.Run method, you can display the main window when the program starts and then create a new window object when you need to switch windows, and display it using the Application.Run method. For example:
Form1 form1 = new Form1();
Application.Run(form1);
- Utilizing MDI (Multiple Document Interface): In an MDI application, you can manage child windows through the parent window’s MdiChildren property, enabling navigation between multiple windows. For example:
Form2 form2 = new Form2();
form2.MdiParent = this; //设置父窗体
form2.Show();
These are common form navigation methods used in WinForm applications, choose the appropriate method based on the specific situation to achieve navigation between forms.