Click here to Skip to main content
Click here to Skip to main content

Object Inspector

, 27 Mar 2006
Rate this:
Please Sign up or sign in to vote.
A complete Object Inspector. Some cool features added.
ObjectInspector.jpg

What's New?

In this update, I add some cool features like:

  • Recompiled for framework2
  • Revisited the graphic interface
  • Added an info panel on the footer
  • More properties are exposed
  • Some refactoring methods are exposed
  • Added the show method list
  • Added the show type attribute
  • Added the preview Control in new Form

Introduction

The framework gives us a useful component to show information about a control. I'm speaking about the property grid. It's a beautiful control but unfortunately it does not list controls, so the user can select a specific control. I try to resolve this problem with this control.

Object Inspector

Object inspector is an advanced property grid that lists and shows every control on the form. When the user selects one item, Object Inspector shows all its properties. An alternative to list all the properties is to click the "Show properties button" that shows this is the form:

propertylist.jpg

Finding All Components

On loading (or when user calls reload), the control scans the form to find every control. The search is obviously recursive and my solutions (maybe not the best...) are shown below:

public void FindChild(Control par)
        {
            foreach (Control cc in par.Controls)
            {                
                    if (cc.Name!=null&&cc.Name!="")
                        this.comboBox1.Items.Add(cc.Name);
                    if(cc.Controls.Count>0)
                        FindChild(cc);                     
            }
        }
        public void FindEach()
        {
            this.comboBox1.Items.Clear();

           if (this.Parent!=null&&this.Parent.Controls.Count>0)
            foreach (Control cc in this.Parent.Controls)
            {
                this.comboBox1.Items.Add(cc.Name);
                if (cc.Controls.Count > 0)
                    FindChild(cc);
            }
        }

Finding the Selected Component

When user selects a controls on the list, this control searches for the right object on the form's control. Also in this case, I use a recursive search. When the right object is found, I send it to the Property grid to show all its features.

public Control FindChildByName(ref string name,Control par)
        {
            Control c=null;
            foreach (Control cc in par.Controls)
            {   
                     if(cc.Name==name)
                      return cc;
                     
                     if(cc.Controls.Count>0)
                     {
                         c=    FindChildByName(ref name,cc);
                         if (c!=null)
                             return c;
                     }                
            }
            return null;
        }
        public Control FindObjectByName(string name)
        {            
           Control c=null ;
           if (this.Parent!=null&&this.Parent.Controls.Count>0)
            
               foreach (Control cc in this.Parent.Controls)
            {               
                if(cc.Name==name)
                    return cc;
                
                if (cc.Controls.Count > 0)
               {
                         c=    FindChildByName(ref name,cc);
                         if (c!=null)
                             return c;
               }
            }
           return null;
        }

Credits

This is only one of the possible solutions. Maybe it is not the best one, but I think that's simple and fast. For any advice, question or problem, please contact me. If you would like to see my other work, please visit my home page at http://zeppaman.altervista.org.

License

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

Share

About the Author

No Biography provided

Comments and Discussions

 
JokeCompatible with framework 1 and 2 PinmemberSir Zeppa'Man28-Mar-06 8:58 
GeneralQuite similar to ... PinmemberTutu7-Dec-05 1:15 
GeneralRe: Quite similar to ... PinmemberSir Zeppa'Man9-Dec-05 3:06 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 28 Mar 2006
Article Copyright 2005 by Sir Zeppa'Man
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid