Form.AddOwnedForm(Form) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
向此窗体添加附属窗体。
public:
void AddOwnedForm(System::Windows::Forms::Form ^ ownedForm);
public void AddOwnedForm (System.Windows.Forms.Form ownedForm);
public void AddOwnedForm (System.Windows.Forms.Form? ownedForm);
member this.AddOwnedForm : System.Windows.Forms.Form -> unit
Public Sub AddOwnedForm (ownedForm As Form)
参数
示例
以下示例演示如何使用 AddOwnedForm 该方法将窗体显示为另一个窗体的自有窗体。 显示拥有的窗体后,可以最小化其所有者表单,拥有的表单将最小化。 该示例要求从窗体的另一个事件或方法调用示例中的代码。
private:
void ShowMyOwnedForm()
{
// Create an instance of the form to be owned.
Form^ ownedForm = gcnew Form;
// Set the text of the form to identify it is an owned form.
ownedForm->Text = "Owned Form";
// Add ownedForm to array of owned forms.
this->AddOwnedForm( ownedForm );
// Show the owned form.
ownedForm->Show();
}
private void ShowMyOwnedForm()
{
// Create an instance of the form to be owned.
Form ownedForm = new Form();
// Set the text of the form to identify it is an owned form.
ownedForm.Text = "Owned Form";
// Add ownedForm to array of owned forms.
this.AddOwnedForm(ownedForm);
// Show the owned form.
ownedForm.Show();
}
Private Sub ShowMyOwnedForm()
' Create an instance of the form to be owned.
Dim ownedForm As New Form()
' Set the text of the form to identify it is an owned form.
ownedForm.Text = "Owned Form"
' Add ownedForm to array of owned forms.
Me.AddOwnedForm(ownedForm)
' Show the owned form.
ownedForm.Show()
End Sub
注解
分配给所有者窗体的表单将保留所有,直到 RemoveOwnedForm 调用该方法。 还可以通过将属性设置为 Owner 对其所有者窗体的引用,使另一个窗体拥有该窗体。
当窗体由另一个窗体拥有时,它将与所有者窗体一起关闭或隐藏。 For example, consider a form named Form2
that is owned by a form named Form1
. 如果 Form1
已关闭或最小化, Form2
则也会关闭或隐藏。 拥有的表单也永远不会显示在其所有者窗体后面。 可以将拥有的窗体用于窗口,例如查找和替换窗口,选择所有者窗体时不应显示在所有者窗体后面。
备注
如果窗体是多文档界面 (MDI) 父窗体,则此属性返回除当前打开的任何 MDI 子窗体之外显示的所有窗体。 若要获取在 MDI 父窗体中打开的 MDI 子窗体,请使用 MdiChildren 该属性。