Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>[It is important to understand that the ISite technique below only works at design time. Because ContainerControl is public and gets assigned a value VisualStudio will write initialization code that sets it at run-time. Site is set at run-time, but you can't get ContainerControl from it]</p> <p><a href="http://www.wiredprairie.us/journal/2004/05/finding_the_component_containe.html" rel="noreferrer">Here's an article</a> that describes how to do it for a non-visual component.</p> <p>Basically you need to add a property ContainerControl to your component:</p> <pre><code>public ContainerControl ContainerControl { get { return _containerControl; } set { _containerControl = value; } } private ContainerControl _containerControl = null; </code></pre> <p>and override the Site property: </p> <pre><code>public override ISite Site { get { return base.Site; } set { base.Site = value; if (value == null) { return; } IDesignerHost host = value.GetService( typeof(IDesignerHost)) as IDesignerHost; if (host != null) { IComponent componentHost = host.RootComponent; if (componentHost is ContainerControl) { ContainerControl = componentHost as ContainerControl; } } } } </code></pre> <p>If you do this, the ContainerControl will be initialized to reference the containing form by the designer. The linked article explains it in more detail.</p> <p>A good way to see how to do things is to look at the implementation of Types in the .NET Framework that have behaviour similar to what you want with a tool such as Lutz Reflector. In this case, System.Windows.Forms.ErrorProvider is a good example to look at: a Component that needs to know its containing Form.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload