The dialog box is either mode or modeless. The mode dialog box must be closed (hidden or uninstalled) before you can continue to operate other parts of the application. For example, if a dialog box requires you to click OK or Cancel before you can switch to another window or dialog box, it is mode.
1. How to call
Any form (class derived from the base class Form) can be displayed in two ways.
//Non-mode form
From qform=new Form();
();
//Mode Form
Form qform=new Form();
();
1. Differences in control
After creating a new form (non-mode), it returns immediately without any relationship between the currently active form and the new form, that is, it is OK to close (or minimize) an existing form while keeping a new window or close (or minimize) a new window while keeping an existing form.
Create a mode form, that is, the original form can only regain control after the created new window is closed. That is, if the new window is not closed, no operation will be performed on the original active window. Minimizing and restoring the new window will be carried out together with the original window, but closing the new window has no effect on the original window.
It should be noted that no matter what the situation is, as long as the main form is closed or the main program is finished, all forms will be closed, regardless of whether it is mode or non-mode.
2. What does the Owner attribute bring?
What is mentioned above is a form when a relationship is not established. When a relationship of ownership is established between forms, the situation will change.
1. First look at the non-modal situation.The way to create a ownership relationship for a non-modal new window is to modify its Owner attribute. (By default, non-mode windows do not have owners)
=this; //Suppose the current window is the owner of the new window
();
Obviously, the newly created non-modal forms have been considered as the child form of the original active form, and the behavior of the original window will affect the new window, so let's call them the relationship between the parent window and the child window.
So, what are the significant changes after the changes? There are two main points:
First, the parent window is minimized, restored or closed, and the child window will also be minimized, restored or closed. (Note that they are irrelevant until the ownership relationship is added.) In turn, minimization, restoration, or closing of child windows has no effect on the parent window.
Second, on the taskbar, only the icon of the parent form is displayed instead of the icon of the child form. (Before the father-son relationship was born, each form had its own icons on the taskbar.)
2. In the case of mode form.When displaying a new form using the ShowDialog method, the current form is considered to be the logical owner of the new form. The so-called logical owner means that by default, if the owner is explicitly specified by ShowDialog, the Owner value is null. But regardless of whether the Owner attribute is set or not, the interaction behavior with the user is the same.
In addition to the same as in the Show case mentioned above, there is another method of setting the Owner attribute, which is to pass it as a parameter of ShowDialog. like:
(this); //The current form is the owner of the new form.
That is to say, if you specify the Owner of the third form as the new mode window, indeed, the new window and the original window may be cut off, but appear as the identity of the child window of the third window. But in fact, the establishment of a father-son relationship between them does not bring us many surprises in terms of behavior. For example, before the new window is closed, the parent window still cannot gain control, etc., all behaviors have not changed.
3. Summary and explanation
1. The form created by the Show method has uncertain behavior, and the Owner attribute is responsible for this.
2. There is an innate relationship between the current active window and the pattern window created with ShowDialog. The carrier of this relationship can be changed, but the establishment or dismantling of this relationship cannot bring any changes to the behavior of the form.
3. A form can have an optional owner and can become the owner of multiple forms at the same time.
4. The child form and parent form referred to here are not in the true sense, but are unscientific names fabricated to deepen understanding. It should be distinguished from the parent and child forms in window form terms and cannot be confused. The latter has edge cropping.
The above article briefly talks about the difference between C# non-mode form show() and mode form showdialog() is all the content I share with you. I hope you can give you a reference and I hope you support me more.