Imports System Public Class Form1 Dim Num As Long = 0 Dim Txt As TextBox Dim Cmb As ComboBox Dim Chec As CheckBox Dim RadB As RadioButton Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() Num = 0 ListControls(Me, True) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() Num = 0 ListControls(Me, False) End Sub Sub ListControls(ByVal parent As Control, ByVal Blocca As Boolean) For Each c As Control In parent.Controls Debug.WriteLine(String.Format("{0} ({1})", c.Name, c.Parent.Name)) If TypeOf c Is TextBox Then Txt = c Txt.ReadOnly = Blocca ElseIf TypeOf c Is ComboBox Then Cmb = c If Blocca = True Then Cmb.DropDownStyle = ComboBoxStyle.Simple Else Cmb.DropDownStyle = ComboBoxStyle.DropDownList End If ElseIf TypeOf c Is CheckBox Then Chec = c Chec.Enabled = Not Blocca ElseIf TypeOf c Is RadioButton Then RadB = c RadB.Enabled = Not Blocca End If ListBox1.Items.Add(Num & " " & c.Name & " - " & c.Parent.Name) Num = Num + 1 If c.Controls.Count > 0 Then ListControls(c, Blocca) End If Next End Sub End Class |