How do I make one form load before the other in C#?
I have two forms in a visual C# forms application. I want to load one form before the other, however it automaticall开发者_StackOverflowy loads form1 first (even though that's the one I want to have load second).
How do I change that?
Look at Program.cs
, which will probably have something like:
Application.Run(new Form1());
Change that to start with the second form.
you need to modify Program.cs
here is sample
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
it is loading Form1.cs by default you can set to load any form
If i want to launch MyForm.cs
then i would change it like
Application.Run(new MyForm());
In your project's properties, you can change wich form is loaded at startup. If I remember correctly, in the Project Explorer dock, if you right-click a form, you can choose the option Set as startup object (or was that only for "sub-projects"?).
精彩评论