Changing label color when the mose moves over it.

T

Timothy Millar

I know this is a simple question. I want to change the background color of a
label when the mouse moves over it. How would I do this?
 
K

Klatuu

Labels don't have events, so the easiest way is to put a rectangle control
around the label with a border style of transparent and special effects of
flat. The use the move move event of the rectangle:

Private Sub Box21_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
With Me.Label13
If .BackColor = 16777215 Then
.BackColor = 8454143
Else
.BackColor = 16777215
End If
End With

End Sub
 
L

Linq Adams via AccessMonster.com

To change the background color when the mouse rolls over the label

Private Sub YourLabel_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
YourLabel.BackColor = vbRed
End Sub

To change the background color back to its original color when the mouse
rolls off of the label

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
YourLabel.BackColor = vbWhite
End Sub
 
L

Linq Adams via AccessMonster.com

Sorry, meant to add the previous code assumes the label is in the Detail
section of the form. If it's in the header or footer section, you'd replace
the

Private Sub Detail_MouseMove()

with

Private Sub FormHeader_MouseMove()

or

Private Sub FormFooter_MouseMove()

Also, if this label resides in the Detail Section of a Continuous form, all
instances of the label will change color.
 
T

Timothy Millar

Here is the coding I used;

Private Sub Box20_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
With Me.Label19
If .BackColor = 16777215 Then
.BackColor = 8454143
Else
.BackColor = 16777215
End If
End With
End Sub

All that happened was that when the mouse moved over the rectangle the text
in the label shifted from normal to slightly bolded.
 
L

Linq Adams via AccessMonster.com

Labels attached to other controls, like textboxes don't have events, but
independent labels most certainly do! They have Click, DoubleClick and the
MouseMover and Mouse up and down events.
 
T

Timothy Millar

I am looking at the details of this label and I have;

On Click
On Dbl Click
On Mouse Down
On Mouse Move
On Mouse Up

Are you sure about labels having no events? I am by far an expert on Access.
 
T

Timothy Millar

I used the following code and received a result of the text font changing
from normal to a slight bold...nothing else;

Private Sub Label19_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Label19.BackColor = vbRed
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top