Form.AddOwnedForm(Form) Form.AddOwnedForm(Form) Form.AddOwnedForm(Form) Form.AddOwnedForm(Form) Method

定义

向此窗体添加附属窗体。Adds an owned form to this form.

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)

参数

ownedForm
Form Form Form Form

此窗体将拥有的 FormThe Form that this form will own.

示例

下面的代码示例演示如何使用AddOwnedForm窗体显示为另一个窗体的附属窗体的方法。The following code example demonstrates how to use the AddOwnedForm method to display a form as an owned form of another form. 附属窗体显示后,你可以尽量减小其所有者窗体和附属窗体将与其降到最低。Once the owned form is shown, you can minimize its owner form and the owned form will minimize with it. 该示例需要在示例代码从另一个事件或窗体的方法调用。The example requires that the code in the example is called from another event or method of a form.

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调用方法。The form assigned to the owner form remains owned until the RemoveOwnedForm method is called. 此外可以通过设置拥有的另一个窗体Owner属性对其所有者窗体的引用。You can also make a form owned by another by setting the Owner property with a reference to its owner form.

当窗体拥有的另一种形式时,它已关闭或隐藏与所有者窗体。When a form is owned by another form, it is closed or hidden with the owner form. 例如,考虑名为窗体Form2归名为窗体Form1For example, consider a form named Form2 that is owned by a form named Form1. 如果Form1已关闭或最小化Form2也会关闭或隐藏。If Form1 is closed or minimized, Form2 is also closed or hidden. 附属窗体也永远不会显示在其所有者窗体后面。Owned forms are also never displayed behind their owner form. 可以使用如查找 windows 附属窗体和替换 windows,不应在选择所有者窗体时显示在所有者窗体。You can use owned forms for windows such as find and replace windows, which should not be displayed behind the owner form when the owner form is selected.

备注

如果窗体多文档界面 (MDI) 父窗体,此属性将返回所有显示除了当前任何 MDI 子窗体的窗体打开。If the form is a multiple-document interface (MDI) parent form, this property returns all forms that are displayed with the exception of any MDI child forms that are currently open. 若要获取在 MDI 父窗体中打开的 MDI 子窗体,请使用MdiChildren属性。To obtain the MDI child forms opened in an MDI parent form, use the MdiChildren property.

适用于

另请参阅