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
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
Go to the source file that contains the "Main" function and just change what Form object is being created,
go to program.cs and change the line:
Application.Run(new Form1());
to whatever form you want.
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.
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();
}
}
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.