Call showdialog () in winform to display the form. Remember to call dispose to release resources.

Source: Internet
Author: User

Under winform

For example

If the mode form displays a new window

New form1 (). showdialog ()

In from1

Closing the form directly or penalizing close () does not actually close the form, but only hides the form.

As for the reason, if close directly destroys the form resource, it is impossible to obtain dialogresult when necessary.

You must call dispose () to close the form.

The following is a description of the mode form in msdn.

You can use this method to display the mode dialog box in the application. When this method is called, the code after this method is executed until the dialog box is closed. You can setDialogresultAssign one of the enumerated values to the dialog box by assigning the value to the dialogresult attribute of the button on the form or setting the dialogresult attribute of the form by using code. This method then returns this value. You can use this return value to determine how to handle the operations in the dialog box. For example, if the dialog box is closedDialogresult. CancelTo prevent execution from being called.ShowdialogCode.

When the form is displayed as a mode dialog box, click the close button (the button with X in the upper right corner of the form) to hide the form andDialogresultSet propertyDialogresult. Cancel. Unlike the mode-free form, when you click the close form button or set in the dialog boxDialogresult. NET Framework does not call the close method. The form can be hidden and re-displayed instead of creating a new instance in the dialog box. Because the form displayed as a dialog box is not closed, you must call the dispose method of the form when your application no longer needs the form.

ShowdialogThis version of the method does not specify a form or control as its owner. When this version is called, the current active window becomes the owner of the dialog box. If you want to specify a specific owner, use another version of this method.

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.