mouseover or hover event (1 Viewer)

CJ_London

Super Moderator
Staff member
Local time
Today, 23:34
Joined
Feb 19, 2013
Messages
14,221
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: 161

isladogs

CID VIP
Local time
Today, 23:34
Joined
Jan 14, 2017
Messages
16,086
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: 291

CJ_London

Super Moderator
Staff member
Local time
Today, 23:34
Joined
Feb 19, 2013
Messages
14,221
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: 298

isladogs

CID VIP
Local time
Today, 23:34
Joined
Jan 14, 2017
Messages
16,086
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:

Users who are viewing this thread

Top Bottom