Click here to Skip to main content
Licence CPOL
First Posted 1 Dec 2005
Views 28,293
Downloads 80
Bookmarked 33 times

Object Inspector

By Sir Zeppa'Man | 27 Mar 2006
A complete Object Inspector. Some cool features added.
1 vote, 5.3%
1
2 votes, 10.5%
2
1 vote, 5.3%
3
2 votes, 10.5%
4
13 votes, 68.4%
5
4.24/5 - 19 votes
1 removed
μ 4.12, σa 2.25 [?]
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)

About the Author

Sir Zeppa'Man



Italy Italy

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
JokeCompatible with framework 1 and 2 PinmemberSir Zeppa'Man9:58 28 Mar '06  
GeneralQuite similar to ... PinmemberTutu2:15 7 Dec '05  
GeneralRe: Quite similar to ... PinmemberSir Zeppa'Man4:06 9 Dec '05  

I wrote this control to only show at runtime the properties of
more than one control at the same time.
 
Now I have reed your article and I find that my control has less
functions than your.
 
So I will update my control to add some others feature...
 
Cool | :cool:
 


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.

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