|
原程序如下:
Private Sub qxz01_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
Call zxzhiduanppp(Me, Me.qxz01)
End Sub
Private Sub qxz02_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
Call zxzhiduanppp(Me, Me.qxz02)
End Sub
Private Sub qxz03_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
Call zxzhiduanppp(Me, Me.qxz03)
End Sub
Private Sub qxz04_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
Call zxzhiduanppp(Me, Me.qxz04)
End Sub
Private Sub qxz05_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
Call zxzhiduanppp(Me, Me.qxz05)
End Sub
以上程序是每当鼠标移动到一个字段后 所触发的过程,
我想把以上代码优化成以下函数,就不必在每一个字中加入移动事件了
以下是照搬“红尘如因”版主的代码,可是运行不了,老是出错,报类型不对。
代码如下:
Private Function ButtonEffectInit(Formolll As Form)
On Error Resume Next
Dim ctl As Control
For Each ctl In Formolll
If ctl.ControlType = acCheckBox Then
If Left(ctl.Name, 3) = "qxz" Then
ctl.OnMouseMove = "= zxzhiduanppp([" & Formolll & " ], [ " & ctl & " ])" 这里老出错,运行不了
End If
End If
Next
End Function
我想这样写了后,就不用每个字段都去写一个移动事件如:
Private Sub qxz03_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
Call zxzhiduanppp(Me, Me.qxz03)
End Sub
我想在 窗体的加载事件中
Private Sub Form_Load()
Call ButtonEffectInit(Me)
End Sub |
|