Form.OwnedForms 属性

定义

获取 Form 对象的数组,这些对象表示此窗体拥有的所有窗体。Gets an array of Form objects that represent all forms that are owned by this form.

public:
 property cli::array <System::Windows::Forms::Form ^> ^ OwnedForms { cli::array <System::Windows::Forms::Form ^> ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form[] OwnedForms { get; }
member this.OwnedForms : System.Windows.Forms.Form[]
Public ReadOnly Property OwnedForms As Form()

属性值

Form[]

Form 数组,它表示此窗体的附属窗体。A Form array that represents the owned forms for this form.

属性

示例

下面的示例演示如何使用 OwnedForms 属性来修改所有者窗体拥有的所有窗体。The following example demonstrates how to use the OwnedForms property to modify all forms owned by the owner form. 该示例中的第一个方法将窗体添加到与附属窗体关联的附属窗体数组。The first method in the example adds forms to the array of owned forms associated with the owned form. 第二种方法遍历所有拥有的窗体并更改标题。The second method loops through all owned forms and changes the caption. 此示例要求两个方法都由事件或窗体的其他方法调用。This example requires that both methods are called by an event or other method of a form.

private:
   void AddMyOwnedForm()
   {
      // Create form to be owned.
      Form^ ownedForm = gcnew Form;

      // Set the text of the owned form.
      ownedForm->Text = String::Format( "Owned Form {0}", this->OwnedForms->Length );

      // Add the form to the array of owned forms.
      this->AddOwnedForm( ownedForm );

      // Show the owned form.
      ownedForm->Show();
   }

   void ChangeOwnedFormText()
   {
      // Loop through all owned forms and change their text.
      for ( int x = 0; x < this->OwnedForms->Length; x++ )
      {
         this->OwnedForms[ x ]->Text = String::Format( "My Owned Form {0}", x );
      }
   }
private void AddMyOwnedForm()
{
   // Create form to be owned.
   Form ownedForm = new Form();
   // Set the text of the owned form.
   ownedForm.Text = "Owned Form " + this.OwnedForms.Length;
   // Add the form to the array of owned forms.
   this.AddOwnedForm(ownedForm);
   // Show the owned form.
   ownedForm.Show();
}

private void ChangeOwnedFormText()
{
   // Loop through all owned forms and change their text.
   for (int x = 0; x < this.OwnedForms.Length; x++)
   {
      this.OwnedForms[x].Text = "My Owned Form " + x.ToString();
   }
}
Private Sub AddMyOwnedForm()
   ' Create form to be owned.
   Dim ownedForm As New Form()
   ' Set the text of the owned form.
   ownedForm.Text = "Owned Form " + Me.OwnedForms.Length.ToString()
   ' Add the form to the array of owned forms.
   Me.AddOwnedForm(ownedForm)
   ' Show the owned form.
   ownedForm.Show()
End Sub


Private Sub ChangeOwnedFormText()
   Dim x As Integer
   ' Loop through all owned forms and change their text.
   For x = 0 To (Me.OwnedForms.Length) - 1
      Me.OwnedForms(x).Text = "My Owned Form " + x.ToString()
   Next x
End Sub

注解

此属性返回一个数组,该数组包含此窗体拥有的所有窗体。This property returns an array that contains all forms that are owned by this form. 若要使窗体成为其他窗体所拥有的窗体,请调用 AddOwnedForm 方法。To make a form owned by another form, call the AddOwnedForm method. 分配给所有者窗体的窗体将保持拥有状态,直到调用 RemoveOwnedForm 方法。The form assigned to the owner form will remain 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 will return 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.

适用于

另请参阅