大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
For Each c As Control In Me.Controls
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、虚拟主机、营销软件、网站建设、通河网站维护、网站推广。
MessageBox.Show(c.ToString())
Next
一个简单的例子,遍历当前Form下所有TextBox并将Text属性设置为空
For Each ct As Control In Me.Controls
If TypeOf ct Is TextBox Then
ct.Text = ""
End If
Next
Private ctrName As String '控件名称
Private isClick As Boolean '鼠标点击状态
'注:如果已知点击目标控件的父控件,ctrParent变量可以不要。
Private WithEvents ctrParent As Control '父控件
Private Sub ControlAMouseDown(sender As Object, e As MouseEventArgs) _
Handles Button1.MouseDown
isClick = (e.Button = MouseButtons.Left _
Or e.Button = MouseButtons.Right) '左键或右键按下
If isClick Then
Dim ctr As Control = CType(sender, Control) '转换Object为控件类型
ctrName = ctr.Name '获取控件名称
ctrParent = ctr.Parent '获取控件的父控件
End If
End Sub
'增加这个父控件事件,是为了正确判别鼠标弹起时是否已进入指定目标
Private Sub ParentMouseMove(sender As Object, e As EventArgs) _
Handles ctrParent.MouseMove '如果已取消ctrParent变量,改为相应的父控件
If isClick Then isClick = False '点击状态关闭
End Sub
Private Sub ControlBMouseUp(sender As Object, e As EventArgs) _
Handles Button2.MouseEnter
If isClick Then '如果点击状态为打开
Dim ctr As Control = CType(sender, Control) '转换Object为控件类型
MsgBox(ctrName " | " ctr.Name) '弹出消息显示结果
End If
End Sub
如果你能确保你的label空间名称是以label开头,并且后面是数字的话,可以通过Sender.Name的方式来获取控件名称,再用Substring来截取后面的数字。
Private
Sub
Label1_MouseEnter(sender
As
Object,
e
As
EventArgs)
Handles
Label1.MouseEnter,
Label2.MouseEnter
'sender.name就是用来获取当前触发事件的控件的名称
Dim
n
As
Integer
n
=
Int(sender.name.ToString.Substring(5))
Call
Menter(n)
End
Sub