What is the difference between Show(), Showdialog() and Application.Run()?

Asked

Viewed 2,601 times

4

I read something about modal but did not understand, someone could explain?

1 answer

3


Let’s start at the beginning, Application.Run(). This is the static method that starts running the entire application window system. This is where the framework takes care of the implementation and starts calling your code as needed.

It is common to pass the first form that should be opened. Only call it without passing a form if the form or forms were created before.

The Show() can only be used in a form object, and it will make the form appear. Whenever it is not shown on the screen you need to use the Hide(), or the Close() which closes the form, and obviously it will no longer be shown.

A normal form is a cooperative component with the application, you can click on any other point of it, can continue having interaction.

ShowDialog() is a special form that is opened and blocks user interaction with the application from being on it until the form is closed. It should only be used in special circumstances, where you really can’t let the user do anything else until he sort out what’s in this form. It can only be called from within a normal form.

Note that the application can continue running normal without user interaction through asynchrony or threads.

  • Loops stop when a form is opened with ShowDialog()?

  • @Francisco does not stop, everything can continue working, but does not let the user act outside the modal. Just do not understand that the loop is a while that go round and round. It talks about loop because he ends up repeating the same general operations. In a certain way if there is no interaction of the screen as a whole by the user or by other elements that influence the application the loop can be considered stopped. This loop is what is called Event driven, then it only works when required. More than this only on a specific question to not get long here.

  • Very good, someday you could make a thread talking about that Event driven...

  • If you have a question about this I’ll answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.