RE: Access form from component by Strider
Strider
Fri Oct 20 05:54:02 CDT 2006
That was a tricky one, no wonder that nobody answered.
First, I added a property named ParentForm to my component:
public Form ParentForm
{
get
{ return m_oParentForm; }
set
{ m_oParentForm = value; }
}
Then, I overrided the IComponent.ISite property in my component and in the
setter part I added the following code:
public override ISite Site
{
get
{ ...}
set
{
IDesignerHost h = (IDesignerHost
)value.Services.GetService(typeof(IDesignerHost) );
this.ParentForm = (Form)h.RootComponent;
}
}
this forces the windows forms designer to add the following
line to the components initialization code:
this.MyComponent.ParentForm = this;
"Strider" wrote:
> Hello.
>
> I have created a custom component. At run-time I need to access the Form
> that is hosting my component from inside my component. Is this possible?
>
> Thanks in advance.