JimDel
JimDel

Reputation: 4359

How do I change what form loads on startup?

I'm using VS2008 and I created an app with a login screen. That screen is no longer needed, and I can't figure out how to change what form loads on startup?

Thanks

Upvotes: 1

Views: 10499

Answers (7)

mirazimi
mirazimi

Reputation: 878

go to program.cs in solution explorer

static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new FrmLogin());
    }

Upvotes: 0

Ezweb
Ezweb

Reputation: 228

In your startup project, you should have a program.cs file.

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

The starting form is Form1. You could change that to whatever form you want.

Upvotes: 2

CSharpAtl
CSharpAtl

Reputation: 7522

You can create an ApplicationContext

Example:

  public class ApplicationLoader : ApplicationContext
    {
        #region main function

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            try
            {

                //Application.EnableVisualStyles();
                Application.Run(new ApplicationLoader());
            }
            catch( System.Exception exc )
            {
                MessageBox.Show( exc.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion

        public ApplicationLoader()
        {
            MainForm = new LoginForm();
        }

        protected override void OnMainFormClosed(object sender, EventArgs e)
        {
            if (sender is LoginForm)
            {
                //change forms
            }
            else
                ExitThread();
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            //catch exception
            Application.Exit();
        }
    }

Upvotes: 1

Matt Warren
Matt Warren

Reputation: 10291

In you Main() function you should have some code like the following:

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

This is where the program starts up the form called MainForm, this is where you need to change the name of the form that runs at startup.

Upvotes: 2

Chris Ballance
Chris Ballance

Reputation: 34367

update this line:

Application.Run(new Form1());

Upvotes: 2

Steven Evers
Steven Evers

Reputation: 17226

go to program.cs and change the line:

Application.Run(new Form1());

to whatever form you want.

Upvotes: 10

BobbyShaftoe
BobbyShaftoe

Reputation: 28499

Go to the source file that contains the "Main" function and just change what Form object is being created,

Upvotes: 2

Related Questions