ARTICLE

Object Inspector in VB.Net

Posted by zeppaman Articles | Visual Basic 2010 December 01, 2006
A cool VB.Net control that allows to control and manage all the controls in a form at runtime.
Download Files:
 
Reader Level:

 

What's new?

In this update I added some cool features like:

  • Recompiled for framework2 
  • Revisited the graphic interface 
  • Added a 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 give us a useful component to show information's about a control. I'm speaking about the property grid. It's a beautiful control but unfortunately it don't 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 list and show every control on the form. When 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 display like this:

Finding all components on loading (or when user call reload) the control scans the form to find every control. The search is obviously recursive and my solutions(maybe not the best...) is shown below:

Public Sub FindChild(ByVal par As Control)

    Dim cc As Control

    For Each cc In par.Controls

        If Not (cc.Name Is Nothing) And cc.Name <> "" Then

            Me.comboBox1.Items.Add(cc.Name)

        End If

        If cc.Controls.Count > 0 Then

            FindChild(cc)

        End If

    Next cc

End Sub 'FindChild

 

Public Sub FindEach()

    Me.comboBox1.Items.Clear()

    If Not (Me.Parent Is Nothing) And Me.Parent.Controls.Count > 0 Then

        Dim cc As Control

        For Each cc In Me.Parent.Controls

            Me.comboBox1.Items.Add(cc.Name)

            If cc.Controls.Count > 0 Then

                FindChild(cc)

            End If

        Next cc

    End If

End Sub 'FindEach

 

Finding the selected component

When user selects a control on the list, this control searches on the form's control the right object. Also in this case I used a recursive search. When the right object has been found, I send it to the property grid to show all its features.

Public Function FindChildByName(ByRef name As String, ByVal par As Control) As Control

    Dim c As Control = Nothing

    Dim cc As Control

    For Each cc In par.Controls

        If cc.Name = name Then

            Return cc

        End If

        If cc.Controls.Count > 0 Then

            c = FindChildByName(name, cc)

            If Not (c Is Nothing) Then

                Return c

            End If

        End If

    Next cc

    Return Nothing

End Function 'FindChildByName

 

Public Function FindObjectByName(ByVal name As String) As Control

    Dim c As Control = Nothing

    If Not (Me.Parent Is Nothing) And Me.Parent.Controls.Count > 0 Then

        Dim cc As Control

        For Each cc In Me.Parent.Controls

            If cc.Name = name Then

                Return cc

            End If

            If cc.Controls.Count > 0 Then

                c = FindChildByName(name, cc)

                If Not (c Is Nothing) Then

                    Return c

                End If

            End If

        Next cc

    End If

    Return Nothing

End Function 'FindObjectByName

 

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 want to see my other work please visit my home page:http://zeppaman.altervista.org

NOTE: THIS ARTICLE IS CONVERTED FROM C# TO VB.NET USING A CONVERSION TOOL. ORIGINAL ARTICLE CAN BE FOUND ON C# CORNER (http://www.c-sharpcorner.com/).

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor