none
Set hover like website on Userform Hyperlink RRS feed

  • Question

  • Hi,

    I want to set the hover, when I move mouse over the userform hyperlink.

    I have used this code

    Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Label1.ForeColor = vbBlue
    Label1.Font.Underline = True
    End Sub

    Its working well, as I expected, but I want to make this link work like web navigations. i.g. when I set over to label, text will be underlined. When I remove my mouse from label it will automatically remove underline.

    Friday, March 22, 2013 2:21 PM

Answers

  • Hi Amit,

    Please have a look at the following code:

    Public X1 As Single
    Public X2 As Single
    Public Y1 As Single
    Public Y2 As Single
    
    Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Label1.ForeColor = vbBlue
    Label1.Font.Underline = True
    End Sub
    
    Private Sub UserForm_Initialize()
    X1 = Label1.Left
    X2 = Label1.Width + X1
    Y1 = Label1.Top
    Y2 = Label1.Height + Y1
    End Sub
    
    
    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If InTheLabelRect(X, Y) Then
        Label1.Font.Underline = True
        Label1.ForeColor = vbBlue
    Else
        Label1.Font.Underline = False
        Label1.ForeColor = vbBlack
    End If
    
    End Sub
    
    Public Function InTheLabelRect(ByVal X As Single, ByVal Y As Single) As Boolean
    If X > X1 And X < X2 Then
        If Y > Y1 And Y < Y2 Then
            InTheLabelRect = True
            Exit Function
        End If
    End If
    
    InTheLabelRect = False
    
    End Function
    

    It checks that if the mouse point is in the rectangle of the label area, then set the underline property.

    Good day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 29, 2013 5:23 AM
    Moderator