我试图在我的表单上使用网页风格的按钮,使用一些图片(ok-off按钮,ok-pressed按钮和ok按钮) 我试着像在网站上那样做。滚动鼠标时更改按钮颜色,单击时再次更改颜色。 但我在这里遗漏了一些东西。我已经实现了在鼠标悬停时更改按钮图像,但是当我点击它时,只更改图片(通过程序MouseMove),但是当我释放鼠标按钮时,事件无法进入mouseUp事件。我错过了什么?
printf
答案 0 :(得分:0)
MouseUP事件发生在同一表单上的MouseDOWN之后,而不是鼠标所在的位置。当你隐藏表单时,你也会停止事件链。
你的案例的解决方案是,而不是隐藏按钮,只显示它前面的另一个..所以当你释放鼠标时,MouseUP事件仍然会发生,结果将是相同的。< / p>
- 按顺序将按钮/图像从后向前放置:确定(c1),关闭(c2),按(c3)
代码:
Private Sub c1_Click()
c1.Visible = False
c2.Visible = True
End Sub
Private Sub c1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
c3.Visible = True
End Sub
Private Sub c1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
c3.Visible = False
End Sub
Private Sub c2_Click()
c1.Visible = True
c2.Visible = False
End Sub
Private Sub c2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
c3.Visible = True
End Sub
Private Sub c2_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
c3.Visible = False
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
c1.Visible = False
c3.Visible = False
c2.Visible = True
End Sub