Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We like to start a Application without a Form (i.e Starting a Class and in this one we want to create the Form instances)

What are the different possiblities?
Posted

If you're talking about System.Windows.Forms.Application, it is always started with some form instance which becomes the application main form: Application.Run(Form) is called. You can create and show some other forms before calling Run. To do this, you can call System.Windows.Forms.Show or System.Windows.Forms.ShowDialog. This is pretty unusual unusual trick used to show some form before the main form on start-up. Nevertheless, the main form remains the one used as a parameter of the call to Application.Run(Form).

That said, you can call any other code before running Application. So, some part of application (non-capitalized) runs before running its Application (capitalized, System.Windows.Forms.Application), but the Application itself always start running with some form.

By the way, there is not such concept as "starting a class". Be accurate if you want to get some help. I still don't know what was your intention. I hope I gave you enough of related information. Your follow-up questions are welcome, but you need to explain your idea and your ultimate goal to get some further help.

—SA
 
Share this answer
 
Comments
Kim Togo 12-May-11 4:49am    
Good explanation. 5.
Sergey Alexandrovich Kryukov 12-May-11 12:28pm    
Thank you, Kim.
--SA
You can start different Form depend on startup parameter etc.

C#
static void Main(string[] args)
{
 if (args.Length > 0 && args[0] == "/help")
 {
   Application.Run(new HelpForm());
 }
 else if (args.Length > 0 && args[0] == "/process")
 {
   ProcessFile f = new ProcessFile();
   f.Work();
   Application.Run(new AllDoneForm());
 }
 else
 {
   Application.Run(new MainForm());
 }
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-May-11 12:29pm    
Well, this is just one of possible examples; my 5.
--SA
Kim Togo 13-May-11 4:28am    
Thanks SA
You just need to create a Windows Forms Application and in static void Main() you can use Application.Run(); without a From parameter, something like this

C#
static void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           //Do Stuff Here
           Application.Run();
       }


It just seems to be a very non standard thing to do, and I personally can't think of a reason to do such a thing.
 
Share this answer
 
Have a look on this[^]

and this one also. might be useful.
Link 1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900