窗体中有若干标签都需要写双击事件,
Private Sub Label0_DblClick(Cancel As Integer)
MsgBox "我是0号标签!"
End Sub
Private Sub Label1_DblClick(Cancel As Integer)
MsgBox "我是1号标签!"
End Sub
Private Sub Label2_DblClick(Cancel As Integer)
MsgBox "我是2号标签!"
End Sub
Private Sub Label3_DblClick(Cancel As Integer)
MsgBox "我是3号标签!"
End Sub
Private Sub Label4_DblClick(Cancel As Integer)
MsgBox "我是4号标签!"
End Sub
Private Sub Label5_DblClick(Cancel As Integer)
MsgBox "我是5号标签!"
End Sub
Private Sub Label6_DblClick(Cancel As Integer)
MsgBox "我是6号标签!"
End Sub
这是7个标签的双击事件,可否用循环指令或其它办法简化其啊!?
[attach]38397[/attach]作者: koutx 时间: 2009-6-13 11:09
一、建一公用模块函数:
Function msgb(ByVal nam As String)
MsgBox "我是" & Right(nam, 1) & "号标签!"
End Function
二、在Label双击事件中:
msgb(me.你的标签名.name)作者: sxgaobo 时间: 2009-6-13 11:29 本帖最后由 sxgaobo 于 2009-6-13 11:32 编辑
怎么做啊?作者: 红尘如烟 时间: 2009-6-14 09:00
Private Sub Form_Load()
Dim ctl As Control
For Each ctl In Me
If TypeOf ctl Is Label Then
ctl.OnDblClick = "=LabelDblClick([" & ctl.Name & "])"
End If
Next
End Sub
Public Function LabelDblClick(Label As Label)
MsgBox "我是" & Val(Mid(Label.Name, 6)) & "号标签!"
End Function作者: sxgaobo 时间: 2009-6-14 11:03 本帖最后由 sxgaobo 于 2009-6-14 15:20 编辑