|
-
Oct 29th, 2002, 08:48 PM
#1
Thread Starter
PowerPoster
Hyperlinks in VB
I just whipped this up, thought it may be of use to people. add this code to a module, and you have the full functionality of a hyperlink in VB. Does display changes for MouseOver etc. Pass the LinkUp the function you want to call for the particular textbox 'link' and you're away. Have fun. 
VB Code:
'Constants
Private Const HYPERLINK_HIGHLIGHT As Long = vbYellow
Private Const HYPERLINK_COLOUR As Long = vbBlue
'Hyperlink code selection flag
Private flgHyperLinkSelected As Boolean
'Depress textbox hyperlink
Public Sub LinkDown(txtLink As TextBox)
'Remove focus from text box
HideCaret txtLink.hwnd
'Change label to selected colour
txtLink.ForeColor = HYPERLINK_HIGHLIGHT
'Enable option selected flag
flgHyperLinkSelected = True
'Remove focus from text box
HideCaret txtLink.hwnd
End Sub
'Highlight textbox hyperlink
Public Sub LinkOver(txtLink As TextBox, X As Single, Y As Single)
'Show highlight image when mouse moves over link text
If Not (flgHyperLinkSelected) Then
With txtLink
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
'Release picture handle
ReleaseCapture
'Unhighlight incident code
txtLink.FontUnderline = True
txtLink.ForeColor = HYPERLINK_COLOUR
Else
'Capture label handle
SetCapture .hwnd
'Highlight incident code
txtLink.FontUnderline = False
txtLink.ForeColor = HYPERLINK_HIGHLIGHT
End If
End With
End If
'Remove focus from text box
HideCaret txtLink.hwnd
End Sub
'Click textbox hyperlink
Public Sub LinkUp(txtLink As TextBox, X As Single, Y As Single, objActionObj As Object, strActionFunc As String, Optional varArgs As Variant)
'Remove focus from text box
HideCaret txtLink.hwnd
'Check mouse location
If (X > 0 And X < txtLink.Width) And (Y > 0 And Y < txtLink.Height) Then
'Call action function
CallByName objActionObj, strActionFunc, VbMethod, varArgs
End If
'Disable selected flag
flgHyperLinkSelected = False
'Release label handle
ReleaseCapture
'Unhighlight incident code
txtLink.FontUnderline = True
txtLink.ForeColor = HYPERLINK_COLOUR
'Remove focus from text box
HideCaret txtLink.hwnd
End Sub
To use:
VB Code:
Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
'Press link
Call LinkDown(Text1(Index))
End Sub
Private Sub Text1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
'Highlight link
Call LinkOver(Text1(Index), X, Y)
End Sub
Private Sub Text1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
'Call LinkUp when mouse up on textbox
Call LinkUp(Text1(Index), X, Y, frmLesson, "FunctionName", Index)
End Sub
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 30th, 2002, 12:39 AM
#2
PowerPoster
jyotiraditya What rjlohan has done is to provide a mouse hover state for the hyperlink, with all the color changes that you see in a browser.
-
Oct 30th, 2002, 01:57 AM
#3
Thread Starter
PowerPoster
Indeed I have. 
I imagine there was another post in this thread, right?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 30th, 2002, 02:10 AM
#4
PowerPoster
Yes, there was a post which showed how to execute the hyperlink.
-
Jan 29th, 2003, 07:16 PM
#5
Fanatic Member
hey im using your code, but whats ReleaseCapture Meant to be? is it a sub that im missing?
-
Jan 29th, 2003, 09:27 PM
#6
Thread Starter
PowerPoster
Apparently I forgot to add the API functions...
ReleaseCapture and HideCaret are Windows API calls. USe the API viewer to find the full declarations.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 29th, 2003, 10:22 PM
#7
Fanatic Member
ah i c, got 'em
ummm its good, although if u click in the textbox to type something it loses focus of the window and nothing happens, which makes it basically impossible to enter anything in the textbox, also if u want 2 edit the contents its impossible to click on the textbox (for editing) without it bringing up IE.
so itd be good if it were a link only when the mouse was over the text and not over the white of the textbox.
this sounds pretty impossible...
-
Jan 29th, 2003, 10:25 PM
#8
Thread Starter
PowerPoster
Well, that's not what this code was designed for. You have to think about design issues too. I have code here to turn a textbox into a hyperlink. Have you ever seen a hyperlink which also acts as an input box?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 29th, 2003, 11:04 PM
#9
PowerPoster
It would make much more since to use a label.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 29th, 2003, 11:09 PM
#10
Thread Starter
PowerPoster
No it wouldn't, which is precisely why I didn't do that. A label doesn't have the requisite Mouse events available.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 29th, 2003, 11:30 PM
#11
PowerPoster
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Jan 29th, 2003, 11:33 PM
#12
Thread Starter
PowerPoster
Can't view it here - wanna give me a brief summary?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 29th, 2003, 11:56 PM
#13
-
Jan 29th, 2003, 11:58 PM
#14
Thread Starter
PowerPoster
That's even more absurd than your last idea... do you have any reason for your comments, or just like to think you're right?
What possible reason would using a picturebox to display text do? I can see no advantage in that.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 30th, 2003, 12:53 AM
#15
-
Jan 30th, 2003, 01:03 AM
#16
Fanatic Member
i rekon a hyperlink in a textbox would be good, for instance i have a form with a sponsor's details and one of the fields is for a website which can be edited, so if the user wishes to visit the website, view the details click on the text in the textbox, and done. if he wishes to edit the website address, click on the white inside the textbox and it is editable, where he then presses save. i guess ill have a button next to the textbox saying Launch or similar.
-
Jan 30th, 2003, 01:15 AM
#17
PowerPoster
You fail to miss the point that the text inside the textbox is not editible.. Far as i can tell the textbox is merely a holder for the link... and serves no other purpose.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 30th, 2003, 01:52 AM
#18
Thread Starter
PowerPoster
Arc, you haven't provided any 'constructive criticism'. All you've done is poonce about throwing around stupid comments with no justification. 
Your stupid posts are just one of the many reasons this site continues to suck arse.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 30th, 2003, 02:18 AM
#19
-
Jan 30th, 2003, 02:27 AM
#20
Thread Starter
PowerPoster
So set the textbox properties: .BorderStyle to None, and set the .Appearance to Flat. Bet Microsoft are real glad a twit like you is proudly displaying his 'qualifications'...
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 30th, 2003, 02:42 AM
#21
PowerPoster
WEll another advantage of the picture box is that you can have Faded text..etc.. You know like thiscouldbealink Overall the picture box offers many more possibilities than a text box if you choose to be creative.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 30th, 2003, 03:07 AM
#22
Thread Starter
PowerPoster
And that requires creating pictures for every link. The textbox option is simpler. If someone really wants rainbow text, which is an utterly horrible design, they can make all the pictures they like.
This doesn't make a picturebox a better option though, does it?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jan 30th, 2003, 03:55 AM
#23
PowerPoster
Well how do you figure that requires pictures? You simply use some API and paint the text on the fly... there is no need for pictures. You could have the user pick 2 colors for each part...Link,Rollover and visited... In fact this wouldnt be a bad idea for an ocx. If you wanted to get real fancy you could even do Shadow/3d text... or Marquee style links that scroll..the skies the limit.
Granted the code is a bit complex, but if you're familiar with
Public Declare Function GradientFillRect Lib "msimg32"Alias " GradientFill" (ByVal hdc As Long, _
pVertex As TRIVERTEX, _
ByVal dwNumVertex As Long, _
pMesh As GRADIENT_RECT, _
ByVal dwNumMesh As Long, _
ByVal dwMode As Long) As Long
Then you should be able to accomplish it wihtout much difficulty.
You may think it's ugly or whatever but i actually think it would be quite innovative and alot of people like Faded text. Too bad theres no way to do it on the web... or maybe there is using xml or something.../shrug
Last edited by Arc; Jan 30th, 2003 at 04:03 AM.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 30th, 2003, 05:08 AM
#24
Fanatic Member
Originally posted by Arc
You fail to miss the point that the text inside the textbox is not editible.. Far as i can tell the textbox is merely a holder for the link... and serves no other purpose.
no i didnt fail to miss that point, therein lies my problem.....
and maybe one day if i make an editable hyperlink textbox ill post it here and shut u both up!
-
Jan 30th, 2003, 07:44 AM
#25
Fanatic Member
MSAccess
Doesn't MSAcess have a thing in a grid where you can edit a field that is also hyperlink (eg where the column is defined as type 'hyperlink')??? You click on the link when viewing the contents of the table...
-
Jan 30th, 2003, 12:09 PM
#26
Someone posted this a while back and it seem pretty good.
VB Code:
Option Explicit
Dim blnClicked As Boolean
Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
' Use this event instead of the click event
blnClicked = True
Me.Print "Clicked"
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Label1
.ForeColor = vbBlue
.Font.Underline = True
'path to hand cursor
.DragIcon = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Cursors\hand.cur")
.Drag vbBeginDrag
End With
End Sub
Private Sub Label1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
If State = vbLeave Then
With Label1
.ForeColor = vbBlack
.FontUnderline = False
.Drag vbEndDrag
End With
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|