The main form is not the parent of the new form. If you use the version of
ShowDialog/Show that take a IWin32Window argument and pass the Mainform to
it, it will be the owner though. In that case you can use the Owner property
in the other form to get a reference to the main form. Still, that property
won't be available in the constructor. You would need to pass a reference to
the constructor if you want to get access to the main form in there.
Sounds unlikely that your main form will be in design mode in this situation
though...
Can you describe what you're trying to accomplish?
/claes
> In a constructor but not the first one executed.
> The main window is already open and I'm opening another form when I do
[quoted text clipped - 64 lines]
>>>
>>> End Function
Thanks for the interest.
Is Owner and Parent the same thing?
> The main form is not the parent of the new form. If you use the version of
> ShowDialog/Show that take a IWin32Window argument and pass the Mainform to
> it, it will be the owner though. In that case you can use the Owner
> property in the other form to get a reference to the main form. Still,
> that property won't be available in the constructor.
The Site and Owner property gets set after the constructor is run?
Is there documentation saying which properties are or are not set before the
constructor is run?
>You would need to pass a reference to the constructor if you want to get
>access to the main form in there.
>
> Sounds unlikely that your main form will be in design mode in this
> situation though...
As I think about it now - I don't think this relates. The problem relates to
the Designer displaying the form and I believe it will use a parameterless
constructor. Also, I have no control of how it shows it.
So I have to be sure not to check Site uintil I know it has been set.
Knowing which events the Designer might raise would also help. (For a form
and also for a usercontrol on a form) I may be checking when I do not have
to. Is that documented?
> Can you describe what you're trying to accomplish?
One example is that I save a forms position in the registry and restore the
position next time it is open.
I don't want to do these things in DesignMode.
There are other similar things.
Thanks again
> /claes
>
[quoted text clipped - 66 lines]
>>>>
>>>> End Function
Claes Bergefall - 05 Mar 2008 10:24 GMT
> Thanks for the interest.
>
> Is Owner and Parent the same thing?
No, not in this case
>> The main form is not the parent of the new form. If you use the version
>> of ShowDialog/Show that take a IWin32Window argument and pass the
[quoted text clipped - 5 lines]
> Is there documentation saying which properties are or are not set before
> the constructor is run?
Basically nothing is set in the constructor so you should avoid doing much
in there.
>>You would need to pass a reference to the constructor if you want to get
>>access to the main form in there.
[quoted text clipped - 6 lines]
> parameterless constructor. Also, I have no control of how it shows it.
> So I have to be sure not to check Site uintil I know it has been set.
Correct, you won't be able to control the constructor that the designer
uses.
> Knowing which events the Designer might raise would also help. (For a form
> and also for a usercontrol on a form) I may be checking when I do not have
> to. Is that documented?
Not that I know of.
>> Can you describe what you're trying to accomplish?
>
> One example is that I save a forms position in the registry and restore
> the position next time it is open.
>
> I don't want to do these things in DesignMode.
In this particular situation you should be able to move your code to the
Load and Closed events. In there you can check the design mode.
/claes