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 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为的窗体,该窗体由名为Form1的窗体拥有。For 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 拥有的窗体(如查找和替换窗口),在选择所有者窗体时,不应在所有者窗体后面显示这些窗体。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.

适用于

另请参阅