Form.OwnedForms 属性

定义

获取 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; }
[<System.ComponentModel.Browsable(false)>]
member this.OwnedForms : System.Windows.Forms.Form[]
Public ReadOnly Property OwnedForms As Form()

属性值

Form[]

Form 数组,它表示此窗体的附属窗体。

属性

示例

以下示例演示如何使用 OwnedForms 属性修改所有者窗体拥有的所有窗体。 示例中的第一个方法将窗体添加到与拥有的窗体关联的自有窗体数组中。 第二种方法遍历所有拥有的窗体并更改标题。 此示例要求这两种方法都由窗体的事件或其他方法调用。

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

注解

此属性返回一个数组,其中包含此窗体拥有的所有窗体。 若要使窗体由另一个窗体拥有,请调用 AddOwnedForm 方法。 分配给所有者窗体的窗体将保持拥有状态, RemoveOwnedForm 直到调用 方法。 还可以通过将 属性设置为 Owner 对其所有者窗体的引用来创建由另一个窗体拥有的窗体。

当窗体由另一个窗体拥有时,它将与所有者窗体一起关闭或隐藏。 例如,请考虑由名为 Form2 的窗体拥有的名为 的 Form1窗体。 如果 Form1 已关闭或最小化, Form2 则也关闭或隐藏。 拥有的窗体也永远不会显示在其所有者窗体的后面。 可以对窗口使用自有窗体,例如查找和替换窗口,在选择所有者窗体时,这些窗体不应显示在所有者窗体后面。

注意

如果窗体是多文档接口 (MDI) 父窗体,则此属性将返回显示的所有窗体,但当前打开的任何 MDI 子窗体除外。 若要获取在 MDI 父窗体中打开的 MDI 子窗体,请使用 MdiChildren 属性。

适用于

另请参阅