Question Hyperlink in a Richtextbox...

arijit08.b

Member
Joined
Nov 1, 2009
Messages
11
Programming Experience
1-3
I have got the code to create a Hyperlink in a richtextbox, I'll share it with you but to the experts, I have a question...

VB.NET:
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  

dim newlabel as new linklabel       

 newlabel.Text = HYPERLINKNAME.text

        newlabel.AutoSize = True 

        newlabel.Location = Me.RichTextBox1.GetPositionFromCharIndex(Me.RichTextBox1.TextLength)  

        Me.RichTextBox1.Controls.Add(newlabel)  

        Me.RichTextBox1.AppendText(newlabel.Text & "   ")  

        Me.RichTextBox1.SelectionStart = Me.RichTextBox1.TextLength  

addhandler newlabel.linkclicked, addressof nwlbl_lnkclckd

    End Sub

VB.NET:
private sub nwlbl_lnkclckd (byval sender as object, byval e as linklabel.linkclickedeventargs)

process.start(THE-LABEL-WHOSE-LINK-WAS-CLICKED-TO-LAUNCH-THIS-EVENT.name.tostring)

end sub

I need to somehow get the NEWLABEL THAT THE PERSON CLICK!

DO you understand what i want to say? It's damn urgent, ive tried everywhere but all those twits don't understand...

Note: the new smileys suck don't they? I liked the earlier ones better!
 
Additional details...

I mean that, in the second code box, in the event of linklabel's linkclicked, i have put that code. now i need to know which linklabel was clicked, there are several which are added at runtime (SO NO, I CAN'T JUST DOUBLE CLICK ON THEM AND TYPE THE CODE BEFORE RUNTIME!)

if i know thru code which linklabel was clicked, then i can write:

VB.NET:
Private Sub  nwlbl_lnkclckd (Blahblahblah... as linklabellinkclickedeventargs)

dim linktostartnow as string = HOW TO GET THAT LABEL.name.tostring

process.start(linktosstartnow)

end sub

please help!
 
The 'sender' event parameter always reference the class instance that raised the event. You can CType/DirectCast it to type Control or LinkLabel. The 'e' event parameter carries additional event info, in this case the type is LinkLabelLinkClickedEventArgs and it has a Link Property that reference the link clicked.
Help for LinkLabel Class (System.Windows.Forms)
 
The 'sender' event parameter always reference the class instance that raised the event. You can CType/DirectCast it to type Control or LinkLabel. The 'e' event parameter carries additional event info, in this case the type is LinkLabelLinkClickedEventArgs and it has a Link Property that reference the link clicked.
Help for LinkLabel Class (System.Windows.Forms)
thanks so much for all this and i don't want to be a pain but, you can see right beside my name is my title - Newbie. How the heck am I supposed to understand what Sender is? Will you PLEASE give me an example?

Okay, tell me, is there a property of the linklabel other than text where I can put a link and it RECOGNIZES it as link? I didn't understand the linkdata property, how to use it otherwise, I used the "e.link" thing and I think this will work but look, at runtime, when the user INSERTS a link, i put it in such a way that the text to show goes as the link's text and the LINK to goto goes in the link's name property but now, in the custom event linklabel_linkclicked, i use the following:

private blahblah

dim runthislink as string=e.link.name.tostring
process.start(runthislink)

end sub


but it gives an error at runtime saying name value is empty, i dont know why , i dont want to know too so what i want to know is:

when the user clicks the insert hyperlink button, the text will go to the text property, where should the link goto? i tried "linklabel$.link=linktextbox.text" but it wont work...

i mean is there any kind of OFFICIAL property for holding links? there is the property of a linklabel - TEXT to hold the TEXT... just like that? and one more thing, can i do the following if there is property like that?

process.start(e.link.officiallinkproperty) or will it say some rubbish about converting values from link to process or from string to link?

you seem pretty senior, i dont want to kill you with confusion but im trying to make the coolest word processor ever, spell check, encrypter, binary-text-html-rtf conversions, etc and it's absolutely necessaryfor it to have hyperlink function, PLEASE PLEASE PLEASE give me an example or rather just answer my Q...
 
If you just plan to use the Text property then you can apply the sender tip I told about, here is a sample how to use CType Function As I said, for the LinkLabel events the sender is the LinkLabel instance that raised the event, so the type is LinkLabel (which inherits Label, which inherits Control).

If you read the help pages you can learn about the more advanced usage of links with the LinkLabel control later. I don't have anything in particular to add to that at this point.
 
you're not getting what I'm telling you to the least.

please just tell me how to use the following:

e.link

^ using which property of the e.link can i retrieve the link and should i set the link to the same property earlier?

just answer this and my work is done... well it's simplest this way.
 
Back
Top