Sebastien Lachance

Windows Forms : Owner and Owned Forms

Since I’m pretty new to Windows Forms I learned a lot this weel (I have a lot more experience in ASP.NET development). I came across this feature and found it really interesting, Owner and Owned Forms. We can say that for the user it’s the same thing as the ShowDialog() method (grayed parent form, etc…). However, with ShowDialog there is no built-in way to make a link between the parent and the child form.

There is 2 way we can make this relation and making the child window aware of the parent:

1. As a parameter in the Show() method

Form1 childForm = new Form1();
childForm.Show(this); //this is the parent form


2. Using the properties

Form1 childForm = new Form1();
childForm.Owner = this; //this is the parent form


And you can iterate through the child form of the parent form with the OwnedForms property.

Comments