Showdialog is required for Singleton mode. If show is used, the following changes must be made:

Source: Internet
Author: User

In C # winformwinformwinformwinform, showshowshowshow and showdialogshowdialogshowdialogshowdialog form. after creating a new form (non-mode), show returns immediately, and no relationship is established between the current active form and the new form, that is, close (or minimize) when the new window is maintained) you can close (or minimize) a new window when the existing form is retained. Form. showdialog create mode form, that is, the original form can regain control only when the new window is closed. That is, if you do not close the new window, you cannot perform any operations on the original activity window. The minimization and restoration of the new window will be performed with the original window, but the close of the new window will not affect the original window. For winform, you may have an inertial understanding or subconscious. When winform is closed (when the close () method is called), it will automatically call dispose. Indeed, for many objects, the close () method calls dispose. However, for winform, it is not always true. Only when winform is displayed in show mode or in non-mode, close will call dispose, that is, the user closes the dialog box in this case, dispose will be called immediately, and resources will be released immediately. However, this is not the case for showdialog and the mode dialog box. You must call dispose to open the new form using the show method in the following two ways, and do not release when closing (1) protected override void onclosing (canceleventargs e) {e. cancel = true; this. hide () ;}( 2) protected override void dispose (bool disposing) {// If (disposing & (components! = NULL) // {// components. dispose (); //} // base. dispose (disposing); hide (); differences between show () and showdialog () in winform:. net 374 people read comments (0) collections report showdialog is like this: display the form as a mode dialog box with the specified owner show is like this: the key to displaying a form with the specified owner is the difference between the mode dialog box and the form. After a simple mode dialog box pops up, you cannot select the main form unless the mode dialog box is closed. After a normal form pops up, you can operate the main form. For the application above, when using the mode dialog box, when showdialogProgram The execution is stopped after the showdialog, and the wait mode dialog box is closed. Therefore, you can set the dialogresult Attribute before closing the dialog box. This. dialogresult = dialogresult. OK; this. Close (); then you can get this value in the main window to determine whether the subwindow is normally closed (the unnormally closed dialogresult is cancel ). However, it is useless to set the form shown in show.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.