Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Links inside rich textbox?

Tags:

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)?

like image 312
Oztaco Avatar asked Mar 24 '12 20:03

Oztaco


People also ask

How do you put a link in rich text?

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.

Does rich text allow hyperlinks?

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.

What is the difference between TextBox and rich TextBox?

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.


2 Answers

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.

like image 85
Mario Fraiß Avatar answered Sep 25 '22 06:09

Mario Fraiß


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());     } 
like image 21
Nima Soroush Avatar answered Sep 24 '22 06:09

Nima Soroush