This documentation is archived and is not being maintained.

Form.AddOwnedForm Method

Adds an owned form to this form.

[Visual Basic]
Public Sub AddOwnedForm( _
   ByVal ownedForm As Form _
)
[C#]
public void AddOwnedForm(
 Form ownedForm
);
[C++]
public: void AddOwnedForm(
 Form* ownedForm
);
[JScript]
public function AddOwnedForm(
   ownedForm : Form
);

Parameters

ownedForm
The Form that this form will own.

Remarks

The form assigned to the owner form remains owned until the RemoveOwnedForm method is called. 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 minimized and closed with the owner form. For example, if Form2 is owned by form Form1, if Form1 is closed or minimized, Form2 is also closed or minimized. Owned forms are also never displayed behind their owner form. 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.

Note   If the form is a multiple document interface (MDI) parent form, this property returns all forms that are displayed with the exception of any MDI child forms that are currently open. To obtain the MDI child forms opened in an MDI parent form, use the MdiChildren property.

Example

[Visual Basic, C#, C++] The following example demonstrates how to use the AddOwnedForm method to display a form as an owned form of another form. Once the owned form is shown, you can minimize its owner form and the owned form will minimize with it. The example assumes that the code in the example is called from another event or method of a form.

[Visual Basic] 
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

[C#] 
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();
}

[C++] 
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 = S"Owned Form";
      // Add ownedForm to array of owned forms.
      this->AddOwnedForm(ownedForm);

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Form Class | Form Members | System.Windows.Forms Namespace | OwnedForms | RemoveOwnedForm | Owner

Show: