Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 96315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:47:44+00:00 2026-05-10T23:47:44+00:00

I have a non-visual component which manages other visual controls. I need to have

  • 0

I have a non-visual component which manages other visual controls.

I need to have a reference to the form that the component is operating on, but i don’t know how to get it.

I am unsure of adding a constructor with the parent specified as control, as i want the component to work by just being dropped into the designer.

The other thought i had was to have a Property of parent as a control, with the default value as ‘Me’

any suggestions would be great

Edit:

To clarify, this is a component, not a control, see here :ComponentModel.Component

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:47:44+00:00Added an answer on May 10, 2026 at 11:47 pm

    [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]

    Here’s an article that describes how to do it for a non-visual component.

    Basically you need to add a property ContainerControl to your component:

    public ContainerControl ContainerControl {   get { return _containerControl; }   set { _containerControl = value; } } private ContainerControl _containerControl = null; 

    and override the Site property:

    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;         }     }   } } 

    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.

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a non-visual component in C# which is designed as a placeholder
Windows Forms allows you to develop Components, non-visual elements that can have a designer.
I have a 32-bit Visual Studio 8.0 C++ Windows DLL (non-.NET) that appears to
I currently have a (non commercial) application created in MS Visual C# 4.5, using
I have non-template class with a templatized constructor. This code compiles for me. But
I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel
We have a non-profit web site that got about 5 million hits in May.
I have a non-Activity class (let's call it NonActivity) that needs to post a
I have a very simple component which trims all leading and trailing spaces from
i have main Application which is Spark component <s:Application xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark minWidth=955 minHeight=600 initialize=initApp();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.