How can I display a hyperlink using a control. I do not want to jump to internet on click of this hyperlink. Simply, need that it function like a button but look like a hyperlink.
1) Make the caption of your label whatever you want and make sure its undelined so that it looks like a hyperlink. I dont know if you can do underlining in a label though.
2) Then change the cursor to a hand when placed over the label using this:
Thanks Elziko.
you are right. I am able to underline the label using FontUnderline property when cursor moves on the label, but even though I take my mouse out, it does not come back to the real label format. How it is possible, using which event or other way.
For cursor, I can use LoadPicture and Click event is also ok for functionality.
I assume you are using mouse move to detect when the mouse moves on to the label. I dont know of an event for when it moves off the label. Heres two MASSIVE bodges if you really need to get it working.
1) Have four labels around the label and detect for a mouse_move event for them which will mean that the mouse has moved away from your first label. Make the surrounding labels invisible.
2) Have a mouse move event for your whole form and decide where the mouse is situated ie. at the same position as the label or not.
I.m sure someone else can suggest a more sensible solution?
Following Form code displays a Hyperlink with the requested behaviour. It also executes the link when Clicked.
The form contains a label lblHyperLink and an ImageBox imgHand. It is used to load a picture of the cursor at Form Load time. Note that its Stretch property is set to true and that its Visible property is set to False. The cursor path is hardcoded into this application (which you shouldn't do)
NOTE[/red] The Label Caption text is NOT underlined in the source code. Somehow this editor recognizes it as a hyperlink and inserts underscores when displaying this text.
'nShowCmd Values
Const SW_HIDE As Long = 0
Const SW_SHOWNORMAL As Long = 1
Const SW_SHOWMINIMIZED As Long = 2
Const SW_SHOWMAXIMIZED As Long = 3
Const SW_MAXIMIZE As Long = 3
Const SW_SHOWNOACTIVATE As Long = 4
Const SW_SHOW As Long = 5
Const SW_MINIMIZE As Long = 6
Const SW_SHOWMINNOACTIVE As Long = 7
Const SW_SHOWNA As Long = 8
Const SW_RESTORE As Long = 9
Const SW_SHOWDEFAULT As Long = 10
'lpOperation Values
Const OP_OPEN As String = "open"
Const OP_PRINT As String = "print"
Const OP_EXPLORE As String = "explore"
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpfile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) _
As Long
Private Sub Form_Load()
With imgHand
.Visible = False
.Stretch = True
.Picture = LoadPicture(c_strHandCursorPath)
End With
With lblLink
.Caption = c_strHyperlink
.AutoSize = True
.ForeColor = vbBlue
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With lblLink
.ForeColor = vbBlue
.FontUnderline = False
.MousePointer = vbDefault
End With
End Sub
Private Sub lblLink_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With lblLink
.ForeColor = vbMagenta
.FontUnderline = True
.MousePointer = vbCustom
.MouseIcon = imgHand.Picture
End With
End Sub
Private Sub lblLink_Click()
Dim lngLaunchError As Long
lngLaunchError = ShellExecute(Me.hwnd, OP_OPEN, lblLink.Caption, 0, 0, SW_SHOWNORMAL)
End Sub
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.