Ack - I asked this question yesterday, and before I read the answer the thread had scrolled off the last page!
I wanted to know how to add a Hyperlink to a form....
(a clickable link to say "VB-World.Net"
Thanks!
Printable View
Ack - I asked this question yesterday, and before I read the answer the thread had scrolled off the last page!
I wanted to know how to add a Hyperlink to a form....
(a clickable link to say "VB-World.Net"
Thanks!
Assuming there is a form with a lblURL label on it
Also make sure you change the lblURL.DragIcon to something else it looks really dumb. ALso in this case it assumes that the URL is in the caption of the label.Code:Private Sub lblUrl_DragDrop(Source As Control, X As Single, Y As Single)
If Source Is lblURL Then
With lblURL
.Font.Underline = False
.ForeColor = vbBlack
Call ShellExecute(0&, vbNullString, .Caption, vbNullString, vbNullString, vbNormalFocus)
End With
End If
End Sub
Private Sub lblUrl_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
If State = vbLeave Then
With lblURL
.Drag vbEndDrag
.Font.Underline = False
.ForeColor = vbBlack
End With
End If
End Sub
Private Sub lblUrl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With lblURL
.ForeColor = vbBlue
.Font.Underline = True
.Drag vbBeginDrag
End With
End Sub
You forgot to include the ShellExecute API function :rolleyes:.
Code: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
Public Const SW_SHOWNORMAL = 1
Usage
ShellExecute Me.hwnd, vbNullString, "http://www.vb-world.net", _
vbNullString, "c:\", SW_SHOWNORMAL
Code:'uses Form1,Image1,Label1
'change the mouse cursor to whatever image you
'for this example I use the hand
'send user to web address on click event of label
Option Explicit
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 Const SW_SHOWNORMAL = 1
Private Sub Form_Load()
Image1.Picture = LoadPicture("C:\Windows\Cursors\Hand-m.cur")
Image1.Visible = False
End Sub
Private Sub Form_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Me.MousePointer = vbDefault
End Sub
Private Sub Label1_Click()
Dim lReturn As Long
lReturn = ShellExecute(hWnd, "open", _
"http://www10.ewebcity.com/dirtbagdog/", _
vbNull, vbNull, SW_SHOWNORMAL)
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = 99
Me.MouseIcon = Image1.Picture
End Sub