We help IT Professionals succeed at work.

how do i have text as a HTML type link in VB?

kenshaw
kenshaw asked
on
Medium Priority
294 Views
Last Modified: 2010-05-01
I have a string that i want to be presented to the user like a HTML link

i.e. - its just a label - but i'd like it to be blue and underlined and when the user mouses over it - the cursor should change to t a hand - and then i should respond to the click event.

how would i do this in VB?
Comment
Watch Question

Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
Well you could get a rough approximation by using the MouseMove events of the Label and Form to switch the Hyperlink formatting on and off:

  Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      Label1.Font.Underline = False
      Label1.ForeColor = vbBlack
  End Sub

  Private Sub Label1_Click()
      MsgBox "Link clicked"
  End Sub

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


Hope this helps.
If the label caption is the site the label should link to, you can open the webpage by:

Private Sub Label1_Click()
    Shell "explorer " & Label1.Caption
End Sub
Hmm, and this code incluiding the 'Hand Cursor' Part



'API Calls
Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long

'Hand Cursor Constant
Private Const IDC_HAND = 32649&

Dim lngHandCursorHandle As Long

Private Sub Form_Load()
    'Initialize hand cursor
    lngHandCursorHandle = LoadCursor(0, IDC_HAND)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label1.Font.Underline = False
    Label1.ForeColor = vbBlack
    Screen.MousePointer = vbDefault
End Sub

Private Sub Label1_Click()
    Shell "explorer " & Label1.Caption
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim lngHandle As Long
    Label1.Font.Underline = True
    Label1.ForeColor = vbBlue
    SetCursor lngHandCursorHandle
End Sub



Atan Asfaloth

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
Hi kensaw!
try the following code:

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = 99
Me.MouseIcon = LoadPicture(App.PATH & "\HARROW.CUR")
End Sub

copy the cursor file to app.path and try this!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.