I know that richtextboxes can detect links (like http://www.yahoo.com) but is there a way for me to add links to it that looks like text but its a link? Like where you can choose the label of the link? For example instead of it appearing as http://www.yahoo.com it appears as Click here to go to yahoo
edit: forgot, im using windows forms
edit: is there something thats better to use (as in easier to format)?
Hover over a page, post, or email and click Edit. In the content editor, click the rich text module where you want to add the link. Highlight the text or image you want to hyperlink. In the rich text toolbar, click the link link icon.
To add a hyperlink using the rich text editor: Select the text or image that you want to use as a link. Click the Hyperlinks tab, then click the Enable as Hyperlink check box.
A TextBox requires less system resources then a RichTextBox and it is ideal when only plain text needs to be edited (i.e. usage in forms). A RichTextBox mainly used if you want more control over styling the text color, type, font, alignment ect. So anything you can do in Microsoft Word, you can do with a RichTextBox.
Of course it is possible by invoking some WIN32 functionality into your control, but if you are looking for some standard ways, check this post out: Create hyperlink in TextBox control
There are some discussions about different ways of integration.
greetings
Update 1: The best thing is to follow this method: http://msdn.microsoft.com/en-us/library/f591a55w.aspx
because the RichText box controls provides some functionality to "DetectUrls". Then you can handle the clicked links very easy:
this.richTextBox1.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBox1_LinkClicked);
and you can simple create your own RichTextBox contorl by extending the base class - there you can override the methods you need, for example the DetectUrls.
Here you can find an example of adding a link in rich Textbox by linkLabel:
LinkLabel link = new LinkLabel(); link.Text = "something"; link.LinkClicked += new LinkLabelLinkClickedEventHandler(this.link_LinkClicked); LinkLabel.Link data = new LinkLabel.Link(); data.LinkData = @"C:\"; link.Links.Add(data); link.AutoSize = true; link.Location = this.richTextBox1.GetPositionFromCharIndex(this.richTextBox1.TextLength); this.richTextBox1.Controls.Add(link); this.richTextBox1.AppendText(link.Text + " "); this.richTextBox1.SelectionStart = this.richTextBox1.TextLength;
And here is the handler:
private void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start(e.Link.LinkData.ToString()); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With