十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Public Sub GetAllControls(ByVal InContainer As Control, ByRef RecieveList As ListBox)
成都创新互联公司是一家专注网站建设、网络营销策划、微信小程序定制开发、电子商务建设、网络推广、移动互联开发、研究、服务为一体的技术型公司。公司成立十年以来,已经为成百上千木制凉亭各业的企业公司提供互联网服务。现在,服务的成百上千客户与我们一路同行,见证我们的成长;未来,我们一起分享成功的喜悦。
For i As Integer = 0 To InContainer.Controls.Count - 1
If InContainer.Controls.Item(i).Text "" Then
GetList.Items.Add(InContainer.Controls.Item(i).Text vbCrLf)
End If
If InContainer.Controls.Item(i).Controls.Count 0 Then
GetAllControls(InContainer.Controls.Item(i), GetList)
End If
Next
End Sub
这段代码可行,但不能遍历菜单和工具栏,要按需要修改
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim TheTypes As Type() = myAssembly.GetTypes()
Dim myType As Type
For Each myType In TheTypes
If myType.BaseType.ToString = "System.Windows.Forms.Form" Then
ListBox1.Items.Add(myType.Name)
End If
Next
End Sub
可以的,需要判断控件类型并做一下类型转换。
For Each c As Control In Me.Controls
If TypeOf(c) Is TextBox Then
Dim t As TextBox = CType(c ,TextBox)
'调用t的方法即可
End If
Next