tags:

views:

71

answers:

3

I'm working with a C# project using System.Windows.Form to create the GUI, I have two forms within the VS project( MainForm and InitialPrompt). I've never used Forms before and Google hasn't been of much help.

Intended action:
InitialPrompt Load
Click Button on InitialPrompt
Load MainForm

However, since MainForm was created first there is some property/method that allows it to load first and the InitialPrompt does not load at all. How to I make MainForm the secondary form and InitialPrompt the primary?

Thanks in advance.

+3  A: 
namespace WindowsFormsApplication1
{
    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());
        }
    }
}

You can change the above code to read

Application.Run(new Form2()); // or whatever the name of the second form is.

This is found in your Program.cs file.

JTA
Thank you! This is exactly what I was looking for.
Eric U.
You're welcome.
JTA
A: 

Like any other .Net project it is the static void Main() method in a class defined in your project. Because of this, only one static void Main() method is allowed in a project.

NOTE: this static Main method must be defined as void return type, and it can either take no arguments, or it can be defined to take an array of strings to be passed as command line arguments.

Charles Bretana
+1  A: 

Look for the Program.cs file inside your project. Inside you will see something like this:

[STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());
    }

Just change new MainForm() to new InitialPrompt(). This will make InitialPrompt the main form.

TskTsk