Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change a label font color a la onMouseOver?

Status
Not open for further replies.

nonturbo

IS-IT--Management
Aug 27, 2001
78
0
0
US
I've got 3 different labels each with associated OnClick events. I'd like the label to change it's Fore Color when the mouse is hovering over, and then back to the original color when the mouse is not over. If I can have the label underline as well would be nice. I'm running Access XP and I'm attempting to simulate the appearance of a hyperlink; but I don't even know where to start. Please Help!!!
TIA!
 
I suspect they may be command buttons, not labels, if they have on click events?

The only way I have managed this in the past is to add code to the 'on mouse over' event of the button, along the lines of

Me![button name].Forecolor = ???

You need the number colour to replace the ??? Standard colour is 0. To see which colours are which you can go to the properties box for your form, chnage the forecolor to the one you want and then see what number comes up- not scientific but it works.

You then need to add the same code to the area around the button (section detail) setting the colour back to 0 on mousemove. Not sure about underlining though!

Nigel

 
Check MSAccess Help:

The MouseMove event applies only to forms, form sections, and controls on a form, not controls on a report.
This event doesn't apply to a label attached to another control, such as the label for a text box. It applies only to "freestanding" labels. Moving the mouse pointer over an attached label has the same effect as moving the pointer over the associated control. The normal events for the control occur; no separate events occur for the attached label.

Create a freestanding label and try this code:

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

[Forms]![YourForm].YourLabel.ForeColor = 255

End Sub

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

[Forms]![YourForm].YourLabel.ForeColor = 0

End Sub

 
The labels are just that, freestanding labels. Not buttons, nor are they attached to anything. Basically, just three labels on a form. I've named them OptionLabel1, OptionLabel2, and OptionLabel3. Freestanding labels can have OnClick events associated with them. That part is all done, debugged, and working great. I just want some visual cues to help the user realize that they are in fact clickable links.. I started writing a Function, and it seems to work for the most part. The only problem I'm having as of now is getting all 3 buttons to go "inactive" when the mouse is not over any of them... xvertex, I'll try your suggestion to get all of the buttons to go inactive. I'll post the working code in a moment for those that may find it useful.
 
It's working like a charm! Anyone know how to get the labels to underline now?

I invoke this code via the On Mouse Move event as =HandleFocus(int), where int = the Label# (1,2, or 3), but this code should work for any number of labels with very slight modification. I have 100 reserved to deactivate all the labels. The labels are in the form footer, so I have the form footer Mouse Move event =HandleFocus(100) and that deactivates them all.

Code:
Private Function HandleFocus(intBtn As Integer)
' This function is called when a label option receives the focus.
' intBtn indicates which button was OnMouseOvered.
' Note: Labels must be named OptionLabel# for this function to work.

Dim intOption As Integer
Const conFontColorBold = 12288004
Const conFontColorNormal = 11316396
Const conLabelCount = 3 ' Set this to the # of labels.

On Error GoTo HandleMouseOver_Err

If intBtn = 100 Then ' turn off all options
    For intOption = 1 To conLabelCount
        Me("OptionLabel" & intOption).ForeColor = conFontColorNormal
    Next intOption
Else
    For intOption = 1 To conLabelCount
        'Show that this menu option has the focus...
        If intOption = intBtn Then
            Me("OptionLabel" & intOption).ForeColor = conFontColorBold
        '... and turn off the focus on the other options
        Else
            Me("OptionLabel" & intOption).ForeColor = conFontColorNormal
        End If
    Next intOption
End If

HandleMouseOver_Exit:
    Exit Function

HandleMouseOver_Err:
    MsgBox "There was an error executing the command.", vbCritical
    Resume HandleMouseOver_Exit
End Function
 
The underline code was pretty easy. Just add this to the appropriate sections.
Code:
Me("OptionLabel" & intOption).FontUnderline = [True/False]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top