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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display a hyperlink

Status
Not open for further replies.

Nanda

Programmer
Nov 14, 2000
104
US
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.

any idea.......
 
I've never tried this but you could:

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:

LabelName.MouseIcon = LoadPicture(c:\winnt\harrow.cur")
LabelName.MousePointer = 99

obviously chang the cursoe path to whever you need too.

3) Then add what ever code you require to the on_click event of the label.

HOWEVER:

I'm 99.9% certain there is a much quicker way to do this, as I'm sure someone will prove........

elziko



 
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.

Thanks again.
 
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?

elziko
 
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.


Const c_strHyperlink As String = "Const c_strHandCursorPath = "C:\Program Files\DevStudio\VB\Graphics\Cursors\H_point.cur"


'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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top