I used two forms in my windows application tha开发者_开发技巧t they aren't my main form. Now I want to close form1 and open form2. How to I do this. Thanx.
Take a look at Hiding and Showing Forms for a good example of various techniques.
Major points include:
- Creating a C# Application Containing Multiple Forms
- Understanding Modal and Non-modal Forms
- Writing C# Code to Display a Non-Modal Form
- Writing C# Code to Display a Modal Form
- Hiding Forms in C#
- Closing Forms in C#
I did this once for my project, to close one application and open another application.
System.Threading.Thread newThread;
Form1 frmNewForm = new Form1;
newThread = new System.Threading.Thread(new System.Threading.ThreadStart(frmNewFormThread));
this.Close();
newThread.SetApartmentState(System.Threading.ApartmentState.STA);
newThread.Start();
And add the following Method. Your newThread.Start will call this method.
public void frmNewFormThread)()
{
Application.Run(frmNewForm);
}
精彩评论