Form.AddOwnedForm(Form) 方法

定義

將這個表單加入附屬的表單。

public:
 void AddOwnedForm(System::Windows::Forms::Form ^ ownedForm);
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

範例

下列範例示範如何使用 AddOwnedForm 方法,將表單顯示為另一個表單的擁有表單。 顯示擁有的表單之後,您可以將其擁有者表單最小化,而擁有的表單將會用它最小化。 此範例需要從表單的另一個事件或方法呼叫範例中的程式碼。

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 呼叫 方法為止。 您也可以使用其擁有者表單的參考來設定 Owner 屬性,讓另一個表單擁有。

當表單是由另一個表單所擁有時,它會與擁有者表單一起關閉或隱藏。 例如,請考慮名為 Form2 的表單,該表單是由名為 的 Form1 表單所擁有。 如果 Form1 已關閉或最小化, Form2 也會關閉或隱藏。 擁有的表單也不會顯示在其擁有者表單後面。 您可以針對視窗使用擁有的表單,例如尋找和取代視窗,在選取擁有者表單時不應該顯示在擁有者表單後面。

注意

如果表單是多文檔介面 (MDI) 父表單,則此屬性會傳回所有顯示表單,但目前開啟的任何 MDI 子表單除外。 若要取得以 MDI 父表單開啟的 MDI 子表單,請使用 MdiChildren 屬性。

適用於

另請參閱