mouseover or hover event (1 Viewer)

CJ_London

Super Moderator
Staff member
Local time
Today, 18:13
Joined
Feb 19, 2013
Messages
16,608
You can use the mousemove event to detect whether the mouse is over a specific control, but you can't tell when it is no longer over the control without using a mousemove or other event such as click from another control or perhaps the section background. But move the mouse quick enough and that event may not fire.

you could perhaps use conditional formatting but that can be problematic again when the mouse is no longer over the control.

Buttons have a hover property and the attached db demonstrates how this effect can be applied to controls on a continuous and single form. Note this does not work for a datasheet view. Neither do buttons :)

The principle is to set the backcolor (or could be the border, forecolor, font size or any appropriate control property) on the mousemove event and to restore it in a form timer event. This solves the issue of needing two (or more) other control events and eliminates the risk of the 'restore' event not firing

There are three forms, the code in all is identical. The code uses API's and these can be farmed out to a standard module, but I chose to have them in the form module since others may have the same or similar API's in their own apps.

There are two versions of the continuous form the first is a 'standard' look, the second with a taller detail section. Both highlight the control in all records,
 

Attachments

  • mouseover.accdb
    560 KB · Views: 418

isladogs

MVP / VIP
Local time
Today, 18:13
Joined
Jan 14, 2017
Messages
18,209
Very neat. Thanks!
I often use mouse move events, to highlight controls or display a message relevant to the control being moved over.
I prefer not to use timer events wherever possible due to possible side effects with flickering - not significant in your example though!
Instead, I normally use the Detail_MouseMove event to clear any message or highlight code ... though that's not needed with this method.

I've added a continuous form 3 which is similar to your form 2 but with slightly more space between controls and all timer code removed.
Otherwise the code is identical to yours
It seems to work equally well as far as I can tell. See what you think.
 

Attachments

  • mouseover_v2_CR.accdb
    500 KB · Views: 548

CJ_London

Super Moderator
Staff member
Local time
Today, 18:13
Joined
Feb 19, 2013
Messages
16,608
it does - but the reason for the timer is to cover the situation where (in the case of no timer) the mouse does not pass over another control calling the mousemove function - unless you have code in the section mousemove event. Otherwise the last control/column highlighted remains highlighted. which may be what you want, or maybe not

Agree it often doesn't matter but there are times when it does, at least to one of my clients!

If you just go for the mouseover event per your example, you don't need the API's and can make sctrl a static variable to the mouseover function - which is what my original code was.

I've attached the db with another form (continuous1a) where I've remove the API's and dependant function, leaving just the mouseover with static sctrl. In this example, it is called from the labels rather than the controls themselves.
 

Attachments

  • mouseover_v3.accdb
    532 KB · Views: 589

isladogs

MVP / VIP
Local time
Today, 18:13
Joined
Jan 14, 2017
Messages
18,209
Hi again
Yes I was aware the APIs and all function apart from MouseOver weren't actually needed for the version of the form I uploaded.
I forgot to delete them from my form 3 before uploading.

Your form 1A works well but you also forgot to remove the TimerInterval =250 line which isn't actually used :)
That is more like the code I normally use for this type of process together with a Detail_MouseMove event to clear the code when not over a control
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:13
Joined
Apr 27, 2015
Messages
6,321
CJL, this came in real handy today. I was able to write a quick sub that changed the OnMousMove property on all my form's command buttons that added a real clean, finished look to my app.

Much appreciated!
 

Users who are viewing this thread

Top Bottom