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
可以的,需要判断控件类型并做一下类型转换。
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
Public Sub ReSetText(Control ctrl)
Dim ct As Control
For Each ct In ctrl.Controls
Try
For Each ct2 As Control In ct.Controls
ReSetText(ct2)
Next
Catch
End Try
If (TypeOf ct Is TextBox) Then
ct.Text = ""
ElseIf (TypeOf ct Is ComboBox) Then
Dim cb As System.Windows.Forms.ComboBox = DirectCast(ct, System.Windows.Forms.ComboBox)
cb.SelectedIndex = -1
End If
Next
End Sub
因为textbox在窗体里的panel里,你只遍历窗体的控件是不够的。