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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make label bold when cursor hovers 1

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
I have a number of labels on a form which when clicked open a range of reports. What I would really like is for the text to go bold when the mouse pointer hovers over the label.
Is this possible? If so how?
 
You could try something with the MouseMove-Event and the fontbold-property (Me.Label.Fontbold = true).

Pampers [afro]
Keeping it simple can be complicated
 
Do this:
Code:
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'Do the same for any other labels that become bold when you hover over them
    lblMyLabel.FontBold = False
End Sub

Private Sub lblMyLabel_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    lblMyLabel.FontBold = True
End Sub
The code in Detail_MouseMove is to turn off the bold font when mouse pointer leaves the area of the label.
 
That works fine thank you.
I have about 60 labels on 1 form. Is there any easy way to do the code to turn off the bold or is it a case of a new line for each label?
 
You could loop through all controls on the form, pick out the labels, and reset the font:
Code:
    Dim anyControl As Control
    
    For Each anyControl In Me.Controls
        If anyControl.ControlType = acLabel Then
            anyControl.FontBold = False
        End If
    Next
 
You can use 2 functions, one to set bold on and one to turn it off. You'll need to create 2 variables that can be used in all procedures of the module. One variable contains the value of the last control you set bold on and the other is used to prevent flickering of the control by only running the code one time when you move the mouse over the control. To set Bold on you need to pass the name of the control that the event is being called from. To turn it off you do not need to pass the control name.

This is the code behind the form:

Option Compare Database
Dim strCtl As String
Dim blnSet As Boolean

Function fSetBold(sI As String)
' this sets Bold on for the control name passed
' it also turns Bold off of the last control
' that was set using this function if it wasn't
' already reset using function fResetBold()
If blnSet = False Then 'prevents flickering
If strCtl <> "" And strCtl <> Null Then
Me(strCtl).Fontbold = False
End If
Me(sI).FontBold = True
strCtl = sI ' store the name of this control to a variable
blnSet = True ' store a value to the variable
End If
End Function

Function fResetBold()
' This turns off Bold when the cursor
' leaves the control and does not need a
' value for the control's name passed because
' it uses the value in the variable strCtl
If blnSet = True Then
If strCtl <> "" Then
Me(strCtl).FontBold = False
End If
blnSet = False
End If
End Function


To call these, you need to add this to the labels
MouseMove Event for each label you want to have affected

= fSetBold("PlaceControlNameHere")


then to turn off the bold add this to the Detail's MouseMove
event. You may also have to add this to the MouseMove event for other controls near the label if you notice that it is not working exactly as expected (i.e. the label is inside an option group, so you also need to add it to the Option Group's MouseMove event).

= fResetBold()

The only time I have problems with this is when the spacing between controls is very, very narrow and the mouse is moved extremely quickly.

You can use this to set various properties of the control, such as FontColor, BackStyle, SpecialEffect, etc,


PaulF
 
I put the new code in the detail MouseMove I presume that was the correct place. It seems to work.
Thank you Joe
 
PaulF
I think our posts crossed. The code form Joeatwork worked but there was some screen flicker so I used your code and everything seems to work fine. I did as you warn, run into a problem with the labels being too close together but that was easily rectified.

Thank you for the code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top