Change link color in RichTextBox
-
21-08-2019 - |
Question
I have a RichTextBox which contains links posted by the users.
The problem is that my RTB makes the color of the links black, and the background color is also black. This leads to the links being invisible.
How do I change the color of the links in the RTB?
Solution
Phoexo:
Have a look at the following CodeProject article. This fellow provides a way to create arbitrary links in the text that work, while the DetectUrls property is set to false. With a small amount of hacking, you should have full control of the formatting of your links.
Links with arbitrary text in a RichTextBox
http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx?display=Print
OTHER TIPS
string str = richTextBox1.Text;
Regex re = new Regex("^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?", RegexOptions.None);
MatchCollection mc = re.Matches(str);
foreach (Match ma in mc)
{
richTextBox1.Select(ma.Index, ma.Length);
richTextBox1.SelectionColor = Color.Red;
}
I'm not sure how to change the color of the links, but you can change the way that the RTB handles URLs.
Try setting the DetectUrls property to false.
That way, the link will be the same color as the RTB text, and visible. (Although not clickable).
You could try changing the formatting in the RichText itself. The fonttbl keyword allows you to do text formats.
http://msdn.microsoft.com/en-us/library/aa140277(office.10).aspx