getting hosting form for a component.

P

Peter Rilling

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?
 
S

solex

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
 
P

Peter Rilling

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.
 
Ö

Özden Irmak

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
 
P

Peter Rilling

Thanks.

Özden Irmak said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top