tags:

views:

22

answers:

2

Hello,

I have a winform that opens (ShowDialog) other winforms.

Is there a way to get the first winform from the opened winform without passing it as a parameter or using a "public static" solution ?

EDIT: Didn't notice that i'm in a user control, how can i get my form?

Thanks in advance.

A: 

What about the Owner property of a form ?

Frederik Gheysels
Thank you very much but please see the edit.
gil
A: 

this.FindForm() will get the form that hosts your custom control. Once you get the form, you can use .Owner property.

IMHO.

Dmitry Karpezo
FindForm returns NULL.
gil
I think FindForm returns the form only if we did .Controls.Add but here we just created a form and opened it.
gil
If so, try iterate .Parent property until you find the first Form object in the chain of parents. P.S. It's quite strange that FindForm() returns null...
Dmitry Karpezo
I meant to say "created UserControl".
gil
If you didn't place the user control to any container then you have no relation to the form.
Dmitry Karpezo