mousemove (1 Viewer)

Jake2

New member
Local time
Yesterday, 19:03
Joined
Jul 22, 2023
Messages
10
I am trying to change the color of text for a command button, then return to the original color after it is passed. I can get the text to change, but the funny thing is that it does not change until the mouse leaves the button, which defeats the purpose of "Mouseover". And I still need to change it back to the original. Solutions?

Cheers,
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:03
Joined
Feb 19, 2002
Messages
43,293
Look again at the mouse events and you will see that they are not appropriate for this task. Events in MouseMove are too annoying for words. Mouse down - fires when you push a mouse button and mouse up - fires when you release it.

Use the control properties to do this.

1694561726558.png
 

Auntiejack56

Registered User.
Local time
Today, 09:03
Joined
Aug 7, 2017
Messages
175
With the text change, you have to make use of the MouseMove event for the button (to change the text), then the MouseMove event for the Detail section of the form (to change it back).
Be careful to leave room around your button. If it is too close to another control or border, the MouseMove event may not fire.

Code:
Option Compare Database
Option Explicit

Dim strCaption As String

Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Change
Me.Command0.Caption = "changed"
End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Change Back
Me.Command0.Caption = strCaption
End Sub

Private Sub Form_Open(Cancel As Integer)
'What to change back to?
    strCaption = Me.Command0.Caption
End Sub

With the colour change, as noted above, use the Hover Color and Hover Fore Color properties of the button.

Jack
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:03
Joined
Feb 19, 2002
Messages
43,293
Properties handle color changes. Not sure why you would write code to do something that is handled by properties.

PS, the code may work but it causes a huge flicker given the times the MouseMove event fires.

Download:
Then create your own form with a few controls and the button you want to change. Don't forget to add logging code to your form so you can see the mouse event firing. And, the form that displays the log events must be open so you can see the events as they are logged.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:03
Joined
Feb 19, 2013
Messages
16,616
Me.Command0.Caption = "changed"
To stop flicker use
Code:
If Me.Command0.Caption <> "changed" and then Me.Command0.Caption = "changed"

However agree with pat since this is about colour not caption - use the hover fore color property
 

Users who are viewing this thread

Top Bottom