Difference in showing forms
-
Hi Anybody knows what is the difference between Application.Run(myForm) and myForm.Show()? Thanks in advance Muthu.
Application.Run(form) runs a message loop, it only return when the form closes. :)
Luc Pattyn
-
Hi Anybody knows what is the difference between Application.Run(myForm) and myForm.Show()? Thanks in advance Muthu.
To Support what Luc said.
Application.Run(myForm); MessageBox.Show("whee!");
Would wait for your form to close to display "whee!", while
myForm.Show() MessageBox.Show("whee!");
Would open your form, then immediately show the messagebox. If I have child forms in windows applications I'm running, I generally use Form.Show() Form.ShowDialog() depending on what I need. ShowDialog acts similarly to Application.Run(), in that it must return before code is executed in the parent, while Show() allows for parallel interaction.
-
To Support what Luc said.
Application.Run(myForm); MessageBox.Show("whee!");
Would wait for your form to close to display "whee!", while
myForm.Show() MessageBox.Show("whee!");
Would open your form, then immediately show the messagebox. If I have child forms in windows applications I'm running, I generally use Form.Show() Form.ShowDialog() depending on what I need. ShowDialog acts similarly to Application.Run(), in that it must return before code is executed in the parent, while Show() allows for parallel interaction.
I seem to remember that you can only have one message pump running per single threaded apartment. So Application.Run would bomb if a form was already loaded in the same apartment, whereas you could open as many form instances as you want with form.show() Russell
-
I seem to remember that you can only have one message pump running per single threaded apartment. So Application.Run would bomb if a form was already loaded in the same apartment, whereas you could open as many form instances as you want with form.show() Russell
Ah, you're right. I was trying to give an example of something visual that the user would see.