I'm trying to use a web-style button on my form, using some pictures(ok-off button, ok-pressed button and ok button) I'm tryin to do the same as in a website. change button color when rolling over the mouse and change color again when click. But I'm missing something here. I have achieved to change the button imagen when mouse is over it, but when i click on it, only change the picture(by procedure MouseMove), but when I release mouse button, event can't go to mouseUp event. WHat am I missing?
Private Sub okpress_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If okpress.Visible = True Then
okoff.Visible = False
okpress.Visible = True
ok.Visible = False
End If
MsgBox "ha entrado", vbOKOnly, "Prueba"
End Sub
Private Sub okoff_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If okoff.Visible = True Or okpress.Visible = True Then
okoff.Visible = False
okpress.Visible = False
ok.Visible = True
End If
End Sub
Private Sub ok_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If okpress.Visible = False Then
okoff.Visible = False
okpress.Visible = True
ok.Visible = False
End If
Dim a As Integer, b As Index, c As Single, d As Single
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ok.Visible = False
okpress.Visible = False
okoff.Visible = True
End Sub
The MouseUP event occurs after a MouseDOWN on the same form, and not where the mouse is. And when you hide the form, you also stop the event chain.
A solution for your case would be, instead of hiding the button, just show the other one in front of it.. So the MouseUP event will still occur when you release the mouse, and the result will be the same.
-- Place the buttons/images from back to front in this order: ok(c1), off(c2), press(c3)
Code:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.