all groups > dotnet windows forms > may 2006 >
You're in the

dotnet windows forms

group:

getting hosting form for a component.


getting hosting form for a component. Peter Rilling
5/13/2006 9:09:28 PM
dotnet windows forms: Hi.

I have a component that interacts with the main form. I would like to have
this component, when initialized, to automatically get a reference to the
form that is hosting it. I was hoping for something as easy as finding the
form that a control is attached to. However, I component has no Parent
property or FindForm method. It is weird because I drag a component onto
the form and yet it does not seem to be associated with the form.

How can I determine the form that a component was dropped onto?

Re: getting hosting form for a component. Peter Rilling
5/13/2006 10:25:15 PM
Yes, I created it. I have looked at the documentation for IContainer and
ISite, but it does not make much sense since I have not developed components
in the past, only controls.

[quoted text, click to view]

Re: getting hosting form for a component. solex
5/14/2006 1:21:59 AM
Peter,
Is this a component that you created, if not there is not much you can do if
the API for the component does not expose a parent property...

Dan


[quoted text, click to view]

Re: getting hosting form for a component. Peter Rilling
5/14/2006 11:23:56 AM
Thanks.

[quoted text, click to view]

Re: getting hosting form for a component. Özden Irmak
5/14/2006 4:38:48 PM
Hello,

if (base.DesignMode && base.Site != null)
{
IDesignerHost IDH =
(IDesignerHost)base.Site.GetService(typeof(IDesignerHost));
if (IDH != null)
{
ContainerControl = (Control)IDH.RootComponent;
}
}

this code should help you...ContainerControl is the reference to the main
form/usercontrol that your component is placed...

Regards,

Özden

[quoted text, click to view]

AddThis Social Bookmark Button