Owner vs Parent vs ParentForm

Form.Owner - Is the Form that "owns" this form. For example a modless

Find/Replace dialog would be Owned by Notepad's main window. If you minimize
the main Form, the owned form will minimize, if you restore the main form,
the owned form will restore... Normally used for "tool" windows in SDI
applications...

Control.Parent - Is the immediate control that this control is placed on.
For example an option button placed in a Panel or GroupBox would have that
Panel or GroupBox as its Parent.

ContainerControl.ParentForm - is the Form that this ContainerControl is
ultimately placed on, however the Parent of the ContainerControl maybe
another ContainerControl, which may have another Control as its Parent,
which may then be a Form. Basically this does a Control.Parent until it
finds a type that inherits from Form.

Hope this helps

 

https://bytes.com/topic/visual-basic-net/answers/386153-owner-vs-parent-vs-parentform

 

 1 public partial class F11 : Form
 2 {
 3     public F11()
 4     {
 5         InitializeComponent();//系统自动构造F11窗体
 6     }
 7 
 8     private void button1_Click(object sender, EventArgs e)//button1的单击事件
 9     {
10         button1.Parent = this;//将button1的父容器改为窗体F11的实例
11         button1.BringToFront();//将button1置于顶层以免被遮挡。
12     }
13 }

其中,button1.Parent=this,这个我一开始是写的button1.Parent=F11
结果不对,原因是F11并非一个实例,它只是一个类。要想取得它的实例,要通过this关键字来取得。

摘引自:https://www.csdn.net/tags/MtjaggzsNDQ2MTktYmxvZwO0O0OO0O0O.html

posted @ 2022-07-30 16:07  chenlight  阅读(47)  评论(0编辑  收藏  举报