What's the difference between Show(), ShowDialog() and Application.Run() functions?
C#WinformsC# Problem Overview
What's the difference between new Show(), ShowDialog() and Application.Run() functions?
In main
(winforms) I saw :
Application.Run(new Form1());
Then, for Form1, I also saw Form1.Show()
with description: "Shows the control to the user."
For ShowDialog, it said "Shows the form as a modal dialog box".
What does this mean?
What are each of their uses and which is most common?
C# Solutions
Solution 1 - C#
The Show
function shows the form in a non modal form. This means that you can click on the parent form.
ShowDialog
shows the form modally, meaning you cannot go to the parent form
Application.Run()
runs the main parent form, and makes that form the main form. Application.Run() is usually found in main
.
Solution 2 - C#
-
Show
displays the form in a non-modal way. -
ShowDialog
displays the form in a modal way. -
Application.Run
starts a message loop for the application and shows the form as the application's main form
Solution 3 - C#
Application.Run() starts the message loop for the windows forms application. At its most basic level it keeps the process alive until the last form is closed.
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.run(v=vs.110).aspx
Show() method shows a windows form in a non-modal state.
http://msdn.microsoft.com/en-us/library/szcefbbd(v=vs.110).aspx
ShowDialog() method shows a window in a modal state and stops execution of the calling context until a result is returned from the windows form open by the method.
http://msdn.microsoft.com/en-us/library/c7ykbedk(v=vs.110).aspx