Click here to Skip to main content
13,189,324 members (64,194 online)
Click here to Skip to main content
Add your own
alternative version


66 bookmarked
Posted 30 Jun 2005

Dynamic Runtime Property Viewer

, 6 Jul 2005
Rate this:
Please Sign up or sign in to vote.
Use the property grid to adjust any control in your application during runtime.

Sample Image - RunTimePropertyViewer.jpg


I have spent just too much time running my applications just so I can see how different color schemes, or other control settings look at runtime. How many times have you restarted your app just so you could see how a control looked with a different background color, or how a grid looks with alternating row colors?

Well, I decided to create this little control that will allow you to specify which types of controls you want to be able to adjust properties on at run time. Keep in mind that this is definitely not a component that you want users to have access to! So, make sure that only developers can open this thing up.

Usage Summary

The 'RunTimePropertyViewer' project is a control library project. Just reference the DLL in your project, and from any screen you will be able to edit the properties of any type of control that lives anywhere on your screen.

The syntax is simple:

RunTimePropertyViewer.PropertyViewer pv = 
         new RunTimePropertyViewer.PropertyViewer(this) ;
pv.Show() ;

How it Works

When you instantiate the PropertyViewer object, you pass in a reference to a ContainerControl. This can be a Form, or any kind of user control that is a ContainerControl.

The constructor of the PropertyViewer will hang on to the ContainerControl reference, but won't do anything until you click the GO button.

There are four choices you have for telling the PropertyViewer what PropertyGrids you want to see:


  1. Include Container Controls - This will make property grids available for any control that is a container control, such as Form, Panel, GroupBox, etc.
  2. Include Standard .NET Data Controls - This will make property grids available for standard data controls. You can change what controls are seen as 'standard' by editing the AddStandardDataControl method.
    private void AddStandardDataControls(Control control)
        if (control.HasChildren)
            foreach (Control child in control.Controls)
                AddStandardDataControls(child) ;
            if (control is TextBoxBase || control is CheckBox || 
            control is DateTimePicker || control is NumericUpDown || 
            control is DataGrid || control is ListBox)
                AddItem(control) ;
                return ;
  3. Include Buttons and Labels - This will make property grids available for any Button or Label.
  4. 'Other Types' - This could be a bit misleading. Basically, you can enter a comma-separated list of any control type, and the property grid will be made available for those types. If for example, you have a custom user control called 'MyControl1', and you want to see property grids for all the 'MyControl1' controls, as well as TextBoxes, you would enter "MyControl1,TextBox" in the 'Other Types' field, and uncheck the other three 'include' checkboxes. This is not case sensitive, but if you misspell a control type, it will be ignored.

Once you hit the GO button, and you get a list of available controls, just navigate the DataGrid to control whose property grid you wish to see. The currencyManager behind the form will 'hook' to the right property grid.

OK, the Code

There are quite a few similar methods in this control, but I'll point out a few of them:


//method to add a control to the SortedList
private void AddItem(object o)
    if (List.ContainsValue(o) == false)
        List.Add(List.Count,o) ;    


//add button and label controls to the list, if this 
//  option is specified
//This is a recursive function, so it will run for every 
//  control on every container control
private void AddButtonsAndLabels(Control control)
    if (control is Button || control is Label)
        AddItem(control) ;
    else if (control.HasChildren)
        foreach (Control child in control.Controls)
            AddButtonsAndLabels(child) ;

AddOtherControls and IsOtherControl

//add other control, as specified in the textbox.  
//NOTE:  if you just wanted to see one type of control, you could enter it here.
//  for example, just enter 'textbox'
private void AddOtherControls(Control control)
    if (IsOtherControl(control))
        AddItem(control) ;
    if (control.HasChildren)
        foreach (Control child in control.Controls)
            //your 'other' control might have more 'other' controls on it
            AddOtherControls(child) ;

//Returns a true if the control type matches what you entered in
//the 'Other' types field.
private bool IsOtherControl(Control control)
    //get the lowercase type of the control
    string ctlType = control.GetType().ToString() ;
    ctlType = ctlType.Substring(ctlType.LastIndexOf(".") + 1).ToLower() ;
    for (int i = otherControls.GetLowerBound(0) ; i 
           <= otherControls.GetUpperBound(0) ; i++ )
        if (ctlType.CompareTo(otherControls[i])==0)
            return true ;
        return false ;  


I have included a demo project, which is an EXE, and I've also included the 'source', which has the test project in it.

Below are 'before' and 'after' images of the TestForm. The properties were changed at runtime through the PropertyViewer.

Before Shot

Sample screenshot

After Shot

Sample screenshot

...And a request

If you like this, please vote.


  • 06-Jul-2005 - Fix to display property grid for first item in list when Go button is pressed.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Paul Brower
Choice Genetics US
United States United States
Seasoned IT Professional. Currently the IT Director for Choice Genetics, and also the world-wide manager for IT Projects related to R&D for Groupe Grimaud (our parent company).

I've spent about half my career as a contractor. I've lived all over the place, but currently reside near St. Louis, Missouri. Moved out here from Roseville, California in Feb-2005. No regrets yet.

Over the recent years I've written software for:
- Disposing of radioactive and toxic waste.
- Disposing of surplus inventory during the Decommission of McClellan Air Force Base.
- Facilitating genetic improvement for Swine Breeding.
- Managing children placed in State custody.
- Dealing with commercial trucking delivery schedules.
- Tracking high resolution images from archeological digs.
- Project Management for the roofing industry.
- Processing engines for credit card transactions.

You may also be interested in...

Comments and Discussions

Generaldynamic property viewer Pin
Paresh Gheewala23-Sep-08 23:03
memberParesh Gheewala23-Sep-08 23:03 
GeneralProperty grid never populated in Demo Pin
SBendBuckeye5-Jul-05 2:32
memberSBendBuckeye5-Jul-05 2:32 
GeneralRe: Property grid never populated in Demo Pin
SBendBuckeye5-Jul-05 2:39
memberSBendBuckeye5-Jul-05 2:39 
GeneralRe: Property grid never populated in Demo Pin
Paul Brower5-Jul-05 13:19
memberPaul Brower5-Jul-05 13:19 
GeneralRe: Property grid never populated in Demo Pin
Paul Brower6-Jul-05 1:27
memberPaul Brower6-Jul-05 1:27 
GeneralRe: Property grid never populated in Demo Pin
SBendBuckeye6-Jul-05 2:35
memberSBendBuckeye6-Jul-05 2:35 
GeneralEnhancement suggestions Pin
fwsouthern30-Jun-05 19:47
memberfwsouthern30-Jun-05 19:47 
GeneralRe: Enhancement suggestions Pin
Paul Brower1-Jul-05 1:18
memberPaul Brower1-Jul-05 1:18 
GeneralAnother approach Pin
Tutu30-Jun-05 12:57
memberTutu30-Jun-05 12:57 
GeneralRe: Another approach Pin
Paul Brower30-Jun-05 13:30
memberPaul Brower30-Jun-05 13:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171016.2 | Last Updated 6 Jul 2005
Article Copyright 2005 by Paul Brower
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid