Export (0) Print
Expand All
Expand Minimize

Form.AddOwnedForm Method

Adds an owned form to this form.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void AddOwnedForm(
	Form ownedForm
)

Parameters

ownedForm
Type: System.Windows.Forms.Form

The Form that this form will own.

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 closed or hidden with the owner form. For example, consider a form named Form2 that is owned by a form named Form1. If Form1 is closed or hidden, 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.

NoteNote:

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.

The following code 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 requires that the code in the example is called from another event or method of a form.

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();
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft