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?
ShowDialog shows the window, disables all other windows in the application, and returns only when the window is closed. This type of window is known as a modal window. Modal windows are primarily used as dialog boxes.
ShowDialog() Shows the form as a modal dialog box. ShowDialog(IWin32Window) Shows the form as a modal dialog box with the specified owner.
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
.
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 formIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With