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!

Mouse hover

Status
Not open for further replies.

assets

Technical User
Oct 23, 2002
574
0
16
AU
I have this code at the top of the form
Code:
Private Function Hover(Optional pstrName As String)
  
    Static sstrHover As String
  
 If sstrHover = pstrName Then Exit Function
    If Len(sstrHover) Then
        ' remove hover effect
        With Me(sstrHover)
            Select Case .ControlType
            Case acTextBox
                .ForeColor = vbBlack
                .FontSize = 11
                .FontBold = True
                If .Controls.Count Then .Controls(0).ForeColor = vbBlack
            Case acRectangle
                .BorderColor = vbBlack
            Case acLabel
                .ForeColor = vbBlack
                .FontSize = 11
                'If .Controls.Count Then .Controls(0).ForeColor = vbBlack
            Case acCommandButton
                .ForeColor = vbBlack
                .FontSize = 11
                .FontBold = True
            End Select
        End With
    End If
    sstrHover = pstrName
    If Len(sstrHover) Then
        ' set hover effect, change font color
        With Me(sstrHover)
            Select Case .ControlType
            Case acTextBox
                .ForeColor = vbRed
                .FontSize = 14
                If .Controls.Count Then .Controls(0).ForeColor = vbRed
            Case acRectangle
                .BorderColor = vbRed
            Case acLabel
                .FontSize = 14
                .ForeColor = vbRed
                'If .Controls.Count Then .Controls(0).ForeColor = vbRed
            Case acCommandButton
                .ForeColor = vbRed
                .FontSize = 14
            End Select
        End With
    End If
  
End Function

And the following on a command button. The same problem exist on all objects. Once the mouse moves over the object it changes to 14pt red but does not chanhe back after you move the mouse back to black.

Code:
Private Sub Command95_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Hover Command95.Name
End Sub

Any help would be appreciated

Never give up never give in.

There are no short cuts to anything worth doing :)
 
I don't quite see what you are expecting to compare in your code:
If Len(sstrHover) Then...

What length string are you expecting to compare / find in variable sstrHover at either of the branches?
 
if it is not equal to pstname then it should be black if equal then red . But it stays red on mose moving off cmd button ot textbox.

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Yes, I understood your intended function, but from what I know of the LEN keyword it returns an integer equal to the number of characters in the string, sstrHover.

As written, I don't think the IF statement compares anything meaningful and probably defaults to NULL, so the code will 'drop through', setting first the black colour and then the red. As red is last to be set that will be what you see. This is because at the end of the 'black tests' your code should exit the function; instead code continues directly into the 'red tests'

If my undertsanding of LEN function is correct I believe your tests needs to be a comparison, someting like:

If Len(sstrHover)= x Then ' do black font, etc
.
.
.
If Len(sstrHover)= y Then ' do red font, etc

 
I gave up and ended using
Code:
 Dim ctlPrevious As String

Function SetBold(frm As Form, strControlName As String)
Const conBold = 700
Const conNormal = 400
    On Error Resume Next
    With frm(ctlPrevious)
        .FontWeight = conNormal
        .ForeColor = 8388608
    End With
    ctlPrevious = strControlName
    With frm(strControlName)
        .FontWeight = conBold
        .ForeColor = 255 '1279872587
    End With
End Function

Function SetNormal(frm As Form)
Const conNormal = 400
    On Error Resume Next
    With frm(ctlPrevious)
        .FontWeight = conNormal
        .ForeColor = 8388608 '0
    End With
End Function

This works for most buttons. But does not solve the text/combo box problem.

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top