tags:

views:

99

answers:

6

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

+2  A: 

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

BobbyShaftoe
+5  A: 

go to program.cs and change the line:

Application.Run(new Form1());

to whatever form you want.

SnOrfus
Awesome thanks!
JimDel
+2  A: 

update this line:

Application.Run(new Form1());
Chris Ballance
+2  A: 

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.

Matt Warren
+1  A: 

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();
     }
    }
CSharpAtl
+2  A: 

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.

Ezweb