Export (0) Print
Expand All

Form.OwnedForms Property

Gets an array of Form objects that represent all forms that are owned by this form.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Form[] OwnedForms { get; }
/** @property */
public Form[] get_OwnedForms ()

public function get OwnedForms () : Form[]

Not applicable.

Property Value

A Form array that represents the owned forms for this form.

This property returns an array that contains all forms that are owned by this form. To make a form owned by another form, call the AddOwnedForm method. The form assigned to the owner form will remain 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.

NoteNote:

If the form is a multiple-document interface (MDI) parent form, this property will return 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 OwnedForms property to modify all forms owned by the owner form. The first method in the example adds forms to the array of owned forms associated with the owned form. The second method loops through all owned forms and changes the caption. This example requires that both methods are called by an event or other method of a form.

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 void AddMyOwnedForm()
{
    // Create form to be owned.
    Form ownedForm = new Form();

    // Set the text of the owned form.
    ownedForm.set_Text("Owned Form " + this.get_OwnedForms().length);

    // Add the form to the array of owned forms.
    this.AddOwnedForm(ownedForm);

    // Show the owned form.
    ownedForm.Show();
} //AddMyOwnedForm

private void ChangeOwnedFormText()
{
    // Loop through all owned forms and change their text.
    for (int x = 0; x < this.get_OwnedForms().length; x++) {
        this.get_OwnedForms()[x].set_Text("My Owned Form " 
            + ((Int32)x).ToString());
    }
} //ChangeOwnedFormText

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft