是否有机会获取Windows窗体中的所有控件名称。 我看到有更新的.net版本的选项,但我在这个项目上限制为1.1 :(
我尝试的是这个但是1.1一切都很难找到......
Public Sub GetAllControlIDs(ByVal c As Windows.Forms.Control, ByVal ids As List(Of String))
ids.Add(c.ID)
If c.HasControls() Then
For Each ch As Windows.Forms.Control In c.Controls
GetAllControlIDs(ch, ids)
Next
End If
End Sub
Private allControlIDs As List(Of String) = New List(Of String)()
答案 0 :(得分:3)
使用.NET 1.1。没有泛型(.NET 2),因此您无法使用List(Of String)
,但可以使用ArrayList
代替:
Public Sub AddAllControlNames(ByVal c As Windows.Forms.Control, ByVal nameList As ArrayList)
nameList.Add(c.Name)
For Each ch As Windows.Forms.Control In c.Controls
AddAllControlNames(ch, nameList)
Next
End Sub
Private allControlNames As ArrayList = New ArrayList()
...
从Form中的某个地方调用(f.e。Load
):
AddAllControlNames(Me, allControlNames)