Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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

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?
0
kenshaw
Asked:
kenshaw
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
 
AtanAsfalothCommented:
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
0
 
AtanAsfalothCommented:
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
0
 
vkaniCommented:
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!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now