Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Show(), ShowDialog() and Application.Run() functions? [duplicate]

Tags:

c#

winforms

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?

like image 432
Edward Karak Avatar asked Dec 31 '13 14:12

Edward Karak


People also ask

What is the purpose of ShowDialog () method?

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.

What is ShowDialog C#?

ShowDialog() Shows the form as a modal dialog box. ShowDialog(IWin32Window) Shows the form as a modal dialog box with the specified owner.


2 Answers

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.

like image 200
Edward Karak Avatar answered Oct 19 '22 21:10

Edward Karak


  • 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
like image 28
Thomas Levesque Avatar answered Oct 19 '22 22:10

Thomas Levesque