新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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
这段代码可行,但不能遍历菜单和工具栏,要按需要修改
c# 用程序转的,也不知道对不对。你看看有没有帮助 ,这是遍历所有控件,还有一个办法就是重载form的消息处理函数应该也是可以的。
STAThread _
Public Shared Sub Main(args As String())
Dim button = New Button()
button.Text = "我是按钮"
button.Dock = DockStyle.Fill
Dim form = New Form()
form.Controls.Add(button)
CapturehMouseClickEvent(form)
form.ShowDialog()
End Sub
Private Shared Sub CapturehMouseClickEvent(control As Control)
AddHandler control.Click, AddressOf ControlOnClick
For Each subControl As Control In control.Controls
CapturehMouseClickEvent(subControl)
Next
End Sub
Private Shared Sub ControlOnClick(sender As Object, eventArgs As EventArgs)
Debug.WriteLine("控制被单击")
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
Exit For 你自己找到后就退出循环了
还有循环的只是已加载的窗体 所以如果你要达到你的目的 可以再软件启动时把所有窗体都 load 有需要加载时 再按你上面的方法去show
可以的,需要判断控件类型并做一下类型转换。
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