59

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?

6
  • 34
    @Servy That comment was even more useless than this one.
    – orfdorf
    Commented May 2, 2015 at 9:53
  • 21
    @Servy I guess you resorted to getting defensive instead of evaluating why your comments are useless. Allow me to explain: It's useless because it answers a question with "just look it up," which is precisely what someone is trying to do when they land on this page and read your comment.
    – orfdorf
    Commented May 6, 2015 at 8:22
  • @SchizoidSpag How is it useless to know that all of the information is in the documentation, which is going to be readily available to them? The entire question itself is useless, as all it's doing is providing a very poor summary of the already readily available information. It ought not to exist, so that people don't find it when searching for this information; they should simply be looking at the documentation.
    – Servy
    Commented May 6, 2015 at 13:55
  • 17
    @Servy You're right, reading 888 words of documentation and deducing the answer from that is far more efficient than reading the 53-word selected answer. Too bad you didn't put your comment as an answer so the rest of us could show our appreciation for it with upvotes.
    – orfdorf
    Commented May 7, 2015 at 14:12
  • 1
    Not an exact duplicate (but the linked question is very useful for anyone wanting the details). I just did a quick google to confirm that the only difference between Show and ShowDialog is that Show is non-modal and ShowDialog is non-modal, and this is the top result.
    – Joey Adams
    Commented Sep 11, 2015 at 13:49

3 Answers 3

117

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.

15
  • 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
8

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.