Controls For Each






Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ControlCount As Integer = Me.Controls.Count - 1
For x As Integer = 0 To ControlCount
For Each c As Control In Me.Controls
If c.TabIndex = x Then
Debug.Print(x & " : " & c.Name & " : " & c.TabIndex)
End If
Next
Next
End Sub



Dim ControlCount As Integer = Me.Controls.Count - 1


FileOpen(1, TypeConn.MyDirPath & "\INI\Campi.txt", OpenMode.Output)





' For x As Integer = 0 To ControlCount


For Each c As Control In Me.Controls

PrintLine(1, " : " & c.Name & " : " & c.TabIndex)

Debug.Print(" : " & c.Name & " : " & c.TabIndex)
If TypeOf c Is TextBox Then
Debug.Print("Text " & c.Name)
PrintLine(1, "Text " & c.Name)
ElseIf TypeOf c Is ComboBox Then
Debug.Print("Combobox " & c.Name)
PrintLine(1, "Combobox " & c.Name)
ElseIf TypeOf c Is Label Then
Debug.Print("Label " & c.Name)
PrintLine(1, "Label " & c.Name)
ElseIf TypeOf c Is DataGridView Then
Debug.Print("DataGridView " & c.Name)
PrintLine(1, "DataGridView " & c.Name)
ElseIf TypeOf c Is CheckBox Then
Debug.Print("CheckBox " & c.Name)
PrintLine(1, "CheckBox " & c.Name)
ElseIf TypeOf c Is Panel Then
Debug.Print("Panel " & c.Name)
PrintLine(1, "Panel " & c.Name)
ElseIf TypeOf c Is Button Then
Debug.Print("Bottone " & c.Name)
PrintLine(1, "Bottone " & c.Name)
ElseIf TypeOf c Is ProgressBar Then
Debug.Print("ProgressBar " & c.Name)
PrintLine(1, "ProgressBar " & c.Name)
ElseIf TypeOf c Is GroupBox Then
Debug.Print("GroupBox " & c.Name)
PrintLine(1, "GroupBox " & c.Name)
ElseIf TypeOf c Is TabControl Then
Debug.Print("TabControl " & c.Name)
PrintLine(1, "TabControl " & c.Name)
ElseIf TypeOf c Is MenuStrip Then
Debug.Print("MenuStrip " & c.Name)
PrintLine(1, "MenuStrip " & c.Name)
ElseIf TypeOf c Is Menu Then
Debug.Print("Menu " & c.Name)
PrintLine(1, "Menu " & c.Name)
Else
PrintLine(1, "**************** " & c.Name)
End If

Next

' Next



FileClose(1)

Shell("Notepad.exe " & TypeConn.MyDirPath & "\INI\Campi.txt", AppWinStyle.MaximizedFocus)











( controlsforeach.html )- by Paolo Puglisi - Modifica del 17/12/2023