Checking if a control exists within a container control?

Posted on 2013-11-14
Last Modified: 2013-11-14
I have a routine that changes various properties of controls. Within this routine, I need to check each control that is passed into it whether or not they are contained within a control. I'm sure this can be done but I've never done it before and don't know how to check for it.

Question by:BlakeMcKenna
  • 3
  • 3
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39648896
What issue(s) are you having with controls that are not contained by something?...we need more details to even begin to help with this one as it's too vague.

Author Comment

ID: 39649037
I'm trying to set the background color of a control that resides within a container control to the container control's background color.
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39649097
Well, that would be difficult to do if said control doesn't have a container!  =)

You can check the Parent() property to see if it has a value.  It it is Nothing, then no container is set:
        If Not IsNothing(ctl.Parent) Then
            ' ... control has a container ...
            ' ... control does NOT have a container ...
        End If

Open in new window

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.


Author Comment

ID: 39649345

With the above code, how can I extract the Parent's BackColor or DefaultBackColor value?
LVL 85

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 39649500
?...Control.Parent() returns type Control.  Just access it!

Assuming it is not Nothing:
ctl.BackColor = ctl.Parent.BackColor

Open in new window


Author Closing Comment

ID: 39649570
Thanks...that worked!

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now