What is the difference between Parentform and Owner

In winforms, we have objForm.Owner and objForm.Parent. What is the difference between the two.

I opened Form B from Form A as a dialog box and expected to access public property forms from Form B using the ParentForm property, but ended up using the Owner property instead of ParentForm being null!

+10
source share
2 answers

Relations between parents and children exist between windows when a child is embedded in the parent window and cannot move outside its borders. Examples are child controls such as TextBox and Panel. And the MDI window model, MDI child windows are embedded in the parent MDI and were born in the black and gray MDI client window.

The owned window belongs to the top-level windows and basically controls their Z-order. Own window is always on top of its owner. It is also minimized and restored along with its owner. Examples are tool windows and dialog boxes.

Note that the form is usually a top-level window and does not have a parent. Thus, he will not use its Parent and ParentForm properties. However, you can turn it into a child window by setting the TopLevel property to false. Sample code here .

+10
source

Form.Owner . It is a form that "owns" this form. For example, the search / replace dialog will belong to the main Notepad window. if you minimize the main form, your own form will be minimized; if you restore the main form, your own form will restore

ContainerControl.ParentForm . This is the form that this ContainerControl container ultimately places on

Mark the article . They are also explained by the Parent.

+2
source

Source: https://habr.com/ru/post/982116/


All Articles