Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using many static many in the Program class which is the default class which holds Main() function

My problem is that if we place any form inside Application.Run() open that form.
But I need to open a form containing five arguments. How can open through Application.Run()

My Second problem is that if I open that form directly by creating an instance and Opening using Show method() it opens only when Application is at the end.

if Application.Run is missing even if we open that form by Show method nothing gets displayed.

Can anyone explain briefly about this problem
Posted
Comments
johannesnestler 5-Aug-14 8:59am    
hard to work with any Windows application Framework if you don't understand how the os handles processce/Windows/message Loops. It seems you are missing some (many) basics - So I'd suggest to "learn" about this topics. And you have to learn your programming language too, - your question alone "open throgh Application.Run()" Shows me you didn't even have learned the "variable" concept. Did't you get that you are just giving a parameter instance of type Form to this method? If you create it there inline (as the pre-generated code does) or if you create your Form before and set all your "arguments" doesn't make a difference just pass an instance! Btw. Application.Run() Starts the Windows message Loop for your main window.

You may use the Application.Run Method (ApplicationContext)[^] for the purpose (see the code sample).
 
Share this answer
 
What happens with
C#
form.Show();
is that this causes the form to display on a separate thread. So what happens in your Main() is that the form is opened, only ever so briefly, then the code keeps executing until the end of main. So this causes the main thread to finish and disposing of any other items. If you like to block the main thread with the form, use
C#
form.ShowDialog();
instead, this blocks the main thread from continuing the process and returns back whenever you close/ dispose of the form.

This can also be done:
C#
static Main(string[] args){
    // ....
    // Some code over here
    // ...
    // ..
    MyForm form = new MyForm(args);

    // Do something else with form

    Application.Run(form);

}
 
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