Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text boxs specific text colour?

Tags:

c#

I want to change text color of Not working Links if link is not working its color should be red. and my links are in textbox

if (!IsLinkWorking(link))
{
     //Here you can show the error. You don't specify how you want to show 
     TextBox2.Text += string.Format(
         "{0}\nNot working\n\n ", link); 
     // this should be in red which is in textbox2.text
}
else
{
    TextBox2.Text += string.Format("{0}\n working\n\n", link);
}
like image 876
yash Avatar asked Dec 11 '25 07:12

yash


1 Answers

You can change the text color of the TextBox with the ForeColor property, but you can not display portions of text in a different color. You will need a RichTextBox, or something similar, for that.

To change the text color of a TextBox control:

TextBox2.ForeColor = System.Drawing.Color.Red;
TextBox2.Text += string.Format("{0}\nNot working\n\n ", link);
like image 140
John Willemse Avatar answered Dec 13 '25 20:12

John Willemse