Form, form, another form

  • Thread starter Thread starter fh1996
  • Start date Start date
F

fh1996

Form.Owner and Form.Parent, what's the difference between them?

Form.ShowDialog() and Form.Show(), when to use which?

Form.Activated(), what does it mean when saying a Form is "activated"?

Thanks!
 
The MSDN library contains a lot of information on those properties and
methods. Here is a quick synopsis:

- Form.Owner is a form that 'owns' this form. When the owner is minimized
or restored, so is this form.

- Form.Parent comes from the fact that a Form is also a control. Every
control can have one parent which is the control with this control inside
it. Usually for a form, this is null.

- Form.ShowDialog() displays the form as a dialog, which means it is stays
on top of the program and code execution stops on the line till the form's
DialogResult property is set (and then is returned).

- Form.Show() simply displays the form normally.

- Form.Activated() brings the form to the top of the screen and gives the
form focus.

Best way to learn more about these is to try them out. Hope this helps.

Cheers,

-Noah Coad
Microsoft MCP & MVP
 
Noah Coad said:
The MSDN library contains a lot of information on those properties and
methods. Here is a quick synopsis:

- Form.Owner is a form that 'owns' this form. When the owner is minimized
or restored, so is this form.

- Form.Parent comes from the fact that a Form is also a control. Every
control can have one parent which is the control with this control inside
it. Usually for a form, this is null.

- Form.ShowDialog() displays the form as a dialog, which means it is stays
on top of the program and code execution stops on the line till the form's
DialogResult property is set (and then is returned).

- Form.Show() simply displays the form normally.

- Form.Activated() brings the form to the top of the screen and gives the
form focus.

Best way to learn more about these is to try them out. Hope this helps.

Cheers,

-Noah Coad
Microsoft MCP & MVP

Thanks!

If in a button's click method of FormA, FormB is craeted:

FormB f = new FormB();
f.ShowDialog();

Then, what's the relatioship between FormA and FormB?
 
In this example, none.

However the usual method of calling ShowDialog is as
follows...

FormB f = new FormB();
f.ShowDialog(this);

In this case FormB.Owner will equal FormA

As mentioned previously, .Parent is almost always null
unless the form is embedded within another control (which
is possible)

Sam
 
Back
Top