Search Forum
(57415 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


              
Printable Version

Object Inspector
By Zeppaman

  • Download source files and demo-425Kb
  • Sample Image - ObjectInspector.jpg

    What's new?

    In this update I added the following features::
    • Recompiled for framework2
    • Revisited the graphic interface
    • Added a info panel on the footer
    • more properties are exposed
    • Some refacrtoring 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 in particular. It's a beautiful control but unfortunately it doesn't list controls, so the user can select a specific control. I try to resolve this probem with this control.

    Object Inspector

    Object inspector is an avanced proprerty grid that list and show every control on the form. Whe user selets one item, Object Inspector show all his properties.An alternative to list all the properties is to click the "Show properties button" that show tis is the form:

    propertylist.jpg


    Finding all components

    On loading(or when user call reload ) the control scan the form to find every control. The search is obviously recoursive and my solutions(maybe not the best...) is 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 select a controls on the list ,this control search on the form's control the right object .Also in this case I use a recoursive search.When the right object has found I send it to the Property grid to show all it's feature.
    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 isn't the better,but I think that's simple and fast.For every advice,question or problem please contact me .