Form.OwnedForms 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 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 屬性。