共用方式為


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 屬性。

適用於

另請參閱