1

I am using the RichTextBox control in Windows Forms to convert RTF to plain text. In the RTF document there is a string like "www.google.com" which the RichTextBox control converts to a URL. However, if I omit the preceding "http" or "www" (e.g. "google.com"), the string is not converted to a URL.

How can I get the RichTextBox control to convert these strings to URLs?

Brett Wolfington
  • 6,587
  • 4
  • 32
  • 51
  • It would help if you add codes exactly how you convert `RTF` to `plain text ` – L_J Jul 29 '18 at 19:07
  • I assume you're talking about this [property](https://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.detecturls(v=vs.110).aspx) when set to true does not converting strings to URL's if they don't begin with www or http. Your only recourse is to parse the text, read each word until you hit a space/tab. If the contents of that string contain more than 1 full stop (period) then assume it's a URL. – Handbag Crab Jul 29 '18 at 19:52

1 Answers1

0

you can use this post and this msdn for guldens - How to: Display Web-Style Links with the Windows Forms RichTextBox Control

The practice is pretty easy: RichTextBox contains LinkClicked property to help you achieve your goal and you use it by invoking event:

this.richTextBox1.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBox1_LinkClicked); 

If you really want, you can extend the base class and create your custom RichTextBox to support DetectUrls.

Barr J
  • 10,636
  • 1
  • 28
  • 46