Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
List all the .Text properties of all controls of an asse
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00930366
Message ID:
00930468
Vues:
9
You put me on the right track!


Here is what I have so far:
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnList.Click
        Dim aAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly  '.LoadFrom("MyAssembly.DLL")
        Dim tType As Type

        lstStatus.Items.Clear()

        For Each tType In aAssembly.GetTypes()
            If TypeIsAForm(tType) Then
                DisplayStatus("Form " & tType.Name, 1)
                Dim oObject As Object = Activator.CreateInstance(tType)
                DisplayStatus("Text = " & CType(oObject, Form).Text, 3)

                Dim oForm As System.Windows.Forms.Form = CType(oObject, System.Windows.Forms.Form)
                ListControls(oForm.Controls, 2)
            End If
        Next tType
    End Sub

    Private Sub ListControls(ByVal pControls As Control.ControlCollection, ByVal pintLevel As Integer)
        For Each ocControl As Control In pControls
            DisplayStatus("Control " & ocControl.Name, pintLevel)
            DisplayStatus("Text = " & ocControl.Text, pintLevel + 1)

            'If the current control is a container, then loop through the controls inside the container
            If ocControl.Controls.Count > 0 Then
                ListControls(ocControl.Controls, pintLevel + 1)
            End If
        Next
    End Sub

    'Tells if an object is a form (because it may inherit from a form)
    Private Function TypeIsAForm(ByVal pType As System.Type) As Boolean
        Do While True
            If pType.FullName = GetType(Windows.Forms.Form).FullName Then
                Return True
            Else
                pType = pType.BaseType
                If pType Is Nothing Then Return False
            End If
        Loop
    End Function

    Private Sub DisplayStatus(ByVal Message As String, ByVal Level As Integer)
        Dim strMessage As String = Space((Level - 1) * 4) + Message
        With Me.lstStatus
            .Items.Add(strMessage)
            .SelectedIndex = .Items.Count - 1
            .Refresh()
        End With
    End Sub
Does anyone know how can do the same for menu items (menus are components instead of controls) ? And for tooltips ?
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform