Is it possible to set the startup form in another cs file besides program.cs from main? Code to set a form as startup object in program.cs from main:
Application.Run(new MyForm());
So for instance, is it possible to set the startup object in Form2, to be Form2, while Form2 is not the startup object (yet hopefully)>?
TO BE SPECIFIC: I wanted to show form2 on startup programmatically, while Form1 was set as startup object. I need to place that code in form2 itself. So I couldn't just simply open Form2 via Form1.
Thanks in advance!
Instead of putting startup logic in forms, you probably would be better served by an ApplicationContext.
http://msdn.microsoft.com/en-us/library/system.windows.forms.applicationcontext(v=vs.110).aspx
Instead of launching a form, you create a class with a [STAThread]Main() function and you make that class your startup object. Within that class you can do some setup (for example, verify that key logging capabilities are present) and then
//ExampleContext is defined as ExampleContext : ApplicationContext
using (ExampleContext exampleContext = new ExampleContext())
{
Application.Run(exampleContext); //The context handles the login and main forms.
}
Inside the application context you can open and close forms freely and you can maintain a global state that will be able to track them. Closing forms won't close your application, allowing you to have multiple forms that appear "top level" to your users.
To exit the application, have your context call Application.Exit()
instead of closing the "main" form (because there isn't such an animal).