Enumerate Control Properties

ChubbyArse

Member
Joined
Jun 10, 2003
Messages
19
How can I enumerate a controls properties in .Net?

I bascially want to do this (vb6 code):

*****Start Code*****
ctl = control
strPropName = "value"

For each prop in ctl.properties
If propr.name = strPropName
msgbox prop.value
Exit For
End if
Next prop
*****Start End*****


Thanks
 
Code:
        Dim ctl As Control
        Dim obj As String = "TextBox1"
        For Each ctl In Me.Controls
            If ctl.Name = obj Then
                MsgBox(ctl.Name & Chr(10) & ctl.Text)
            Else
                MsgBox(ctl.Name)
            End If
        Next

or if you want to get the controls on your form by Type and list them / get the handles :
Code:
        Dim ctl As Control
        For Each ctl In Me.Controls
            If TypeOf ctl Is TextBox Then
                MessageBox.Show("textbox : " & ctl.Handle.ToInt32 & Chr(10) & ctl.Name)
            Else
                MessageBox.Show("other control : " & ctl.Handle.ToInt32 & Chr(10) & ctl.Name)
            End If
        Next
 
You can use Reflection to enumerate over the properties of an object. Look in to TypeDescriptor.GetProperties().
 
Back
Top