且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

循环遍历表单中的所有文本框,包括分组框内的文本框

更新时间:2023-11-03 08:37:34

你可以使用这个功能,linq 可能是一种更优雅的方式.

You can use this function, linq might be a more elegant way.

Dim allTxt As New List(Of Control)
For Each txt As TextBox In FindControlRecursive(allTxt, Me, GetType(TextBox))
   '....'
Next

Public Shared Function FindControlRecursive(ByVal list As List(Of Control), ByVal parent As Control, ByVal ctrlType As System.Type) As List(Of Control)
    If parent Is Nothing Then Return list
    If parent.GetType Is ctrlType Then
        list.Add(parent)
    End If
    For Each child As Control In parent.Controls
        FindControlRecursive(list, child, ctrlType)
    Next
    Return list
End Function