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.