Font change on mouseover

S

stacie.2410

I have a form which has several labels (which are tied to actions when
they're clicked). I'm looking for a solution to change the color of the font
when it's moused over. The original font is blue, and I want to change it to
yellow on mouseover, then back to blue when the mouse is no longer hovering
over that label. I've got some code currently in that will change the color
of the font when it's moused over. but it doesn't change it back afterwards,
despite my code on the form's mouseover event. It just stays yellow, Any
help is greatly appreciated. I've pasted my code below.

Private Sub AddTransmittal_MouseMove(Button As Integer, Shift As Integer, X
As Single, Y As Single)
AddTransmittal.FontSize = 13
AddTransmittal.ForeColor = 49915
End Sub

Private Sub MainMenu_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
AddTransmittal.FontSize = 12
AddTransmittal.ForeColor = 16776960
End Sub
 
S

Stuart McCall

stacie.2410 said:
I have a form which has several labels (which are tied to actions when
they're clicked). I'm looking for a solution to change the color of the
font
when it's moused over. The original font is blue, and I want to change it
to
yellow on mouseover, then back to blue when the mouse is no longer
hovering
over that label. I've got some code currently in that will change the
color
of the font when it's moused over. but it doesn't change it back
afterwards,
despite my code on the form's mouseover event. It just stays yellow, Any
help is greatly appreciated. I've pasted my code below.

Private Sub AddTransmittal_MouseMove(Button As Integer, Shift As Integer,
X
As Single, Y As Single)
AddTransmittal.FontSize = 13
AddTransmittal.ForeColor = 49915
End Sub

Private Sub MainMenu_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
AddTransmittal.FontSize = 12
AddTransmittal.ForeColor = 16776960
End Sub

If you really mean the form's mousemove event (as opposed to a 'container'
control) then:

Private Sub MainMenu_MouseMove

should be:

Private Sub Form_MouseMove
 
S

stacie.2410

I made the change you mentioned, but it's still not changing the color back
to blue after it's changed to yellow upon mouseover. Is there some setting
that I could be missing that's causing it to not change it back?
 
L

Linq Adams via AccessMonster.com

The code to return to the original formatting needs to be in the MouseMove
event of the appropriate ***Section*** of the form (i.e. Detail, Header,
Footer) not to the form as a whole.
 
S

stacie.2410

I have made that change, but the problem still persists. It will change from
blue to yellow, but will not change back to blue afterwards. Here is my
code, is there something I'm missing?

Private Sub AddTransmittal_MouseMove(Button As Integer, Shift As Integer, X
As Single, Y As Single)
AddTransmittal.FontSize = 13
AddTransmittal.ForeColor = 49915
End Sub


Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
AddTransmittal.FontSize = 12
AddTransmittal.ForeColor = 16776960
End Sub
 
L

Linq Adams via AccessMonster.com

And AddTransmittal is in the Detail Section, not the Header or Footer Section?
 
D

Dirk Goldgar

stacie.2410 said:
I have made that change, but the problem still persists. It will change
from
blue to yellow, but will not change back to blue afterwards. Here is my
code, is there something I'm missing?

Private Sub AddTransmittal_MouseMove(Button As Integer, Shift As Integer,
X
As Single, Y As Single)
AddTransmittal.FontSize = 13
AddTransmittal.ForeColor = 49915
End Sub


Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
AddTransmittal.FontSize = 12
AddTransmittal.ForeColor = 16776960
End Sub


Is there enough of the Detail section showing around the button that its
MouseMove event has a chance to fire? If you move quickly enough that the
mouse pointer is only over the section background for an instant, it's
possible that the event won't fire.

Aside from that, I'd recommend only changing the label's properties when
they aren't already what you want, like this:

'------ start of example code ------
Private Sub AddTransmittal_MouseMove(Button As Integer, Shift As Integer, X
As Single, Y As Single)

With Me.AddTransmittal
If .FontSize <> 13 Then
.FontSize = 13
.ForeColor = 49915
End If
End With

End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

With Me.AddTransmittal
If .FontSize <> 12 Then
.FontSize = 12
.ForeColor = 16776960
End If
End With

End Sub
'------ end of example code ------
 
S

stacie.2410

Ah...I figured out what the problem was. I'm using a picture as a background
image and even though it's "sent to back", when you "unhover" the mouse from
the label, instead of it acting as if it's mousing over the detail, it's
mousing over the background image. Is there a solution for this?
 
S

stacie.2410

Additionally, I need to add the code for the remainder of the labels, and
obviously I can modify the code that goes behind each label, but how do I
modify the code for the detail to set the "else" for the other labels? Sorry
for so many questions...this is kinda new to me. Thanks for your help.
 
S

stacie.2410

I actually got the mouseover effect to work for the first label with the
picture as the background...the only thing I need help figuring out is how to
set the default code for all 4 labels now, instead of just the one
(AddTransmittal).
 
D

Dirk Goldgar

stacie.2410 said:
I actually got the mouseover effect to work for the first label with the
picture as the background...the only thing I need help figuring out is how
to
set the default code for all 4 labels now, instead of just the one
(AddTransmittal).

What did you do to cope with the backgrund image, use its MouseMove event as
well?

To generalize the code, I would do the following:

1. Set the Tag property of each of the labels to be highlighted to
"HighLight". If you aren't familiar with it, you'll find the Tag property
on the Other tab of each label's property sheet.

2. Create the following functions in the General section of the form's code
module (not associated with any control):

'------ start of code -- warning: air code ------
Function HighlightControl(ControlName As String)

With Me.Controls(ControlName)
If .FontSize <> 13 Then
.FontSize = 13
.ForeColor = 49915
End If
End With

End Function

Function UnhighlightControls()

Dim ctl As Access.Control

For Each ctl In Me.Controls
With ctl
If .Tag = "Highlight" Then
If .FontSize <> 12 Then
.FontSize = 12
.ForeColor = 16776960
End If
End If
End With
Next ctl

End Function
'------ end of code ------

3. With those functions in place, remove the MouseMove event procedures you
currently have (if they are related to this highlighting business), and do
the following.

3a. Set the On MouseMove property (right there on the property sheet) of
each of the labels to be highlighted to a function expression like this:

=HighlightControl("<your label name>")

Use the name of the label control for <your label name> in each case. For
example, for the AddTransmittal label, the On MouseMove property would read:

=HighlightControl("Addtransmittal")

3b. Set the OnMouseMove property of the Detail section, and of that
background image control if you need to, to this:

=UnhighlightControls()

That ought to do it.
 

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

Similar Threads


Top