Skip to main content
Email Password   helpLost your password?

Sample Image - ObjectInspector.jpg

What's new?

In this update I add some coll features like:

Introduction

The framework give us a usefull component to Show informations about a control. I'm speaking about The property grid.It's a beautiful control but unfortunately it dont list controls ,so the user can select a specific control.I try to resolve thi probem with thi 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 . If You would see my other work please visit my home page: http://zeppaman.altervista.org



You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
JokeCompatible with framework 1 and 2 Pin
Sir Zeppa'Man
9:58 28 Mar '06  
GeneralQuite similar to ... Pin
Tutu
2:15 7 Dec '05  
GeneralRe: Quite similar to ... Pin
Sir Zeppa'Man
4:06 9 Dec '05  


Last Updated 27 Mar 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009