Berikut ini saya bagikan lagi sebuah trik membuat Label menjadi Link. Karena jarangnya komponen label yang bisa dibuat agar bisa nge-Link ke sebuah website maka saya dapatkan sebuah trik yang bisa nge-Link.
Berikut ini langkah pembuatannya:- Tambahkan sebuah Label ke dalam Form yan aktif.
- Setelah itu, ketikkan kode di bawah ini.
Private Declare Function LoadCursor Lib "user32.dll" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As LongUntuk sample programnya Anda bisa men-download-nya disini atau disini.
Private Declare Function SetCursor Lib "user32.dll" (ByVal hCursor As Long) As Long
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()
Label1.ForeColor = vbBlue
Label1.FontUnderline = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Label1.ForeColor <> vbBlue Then Label1.ForeColor = vbBlue
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetCursor (LoadCursor(0, 32649))
ShellExecute Me.hwnd, "", "http://oknaburage.blogspot.com", "", "", vbMaximizedFocus 'Ganti http://oknaburage.blogspot.com dengan Link yang akan dituju.
Label1.ForeColor = vbBlue
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetCursor (LoadCursor(0, 32649))
If Label1.ForeColor <> vbRed Then Label1.ForeColor = vbRed
End Sub