如何打印彩色文字

时间:2011-10-17 08:43:16

标签: c# colors

if (counter == 0)
     textBox2.Text += "ERROR: the item in the  " + j + "th row is wrong" + Environment.NewLine;

如何在TextBox中显示j变量Red?

3 个答案:

答案 0 :(得分:3)

您只需更改整个字体的颜色即可。使用textBox2.ForeColor = Color.Red

或使用RichTextBox

答案 1 :(得分:2)

首先,将其设为富文本框而不是常规文本框。

然后

Font fnt=new Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point);
string mystring=@" " + j + "th";
if (richTextBox1.Find(mystring)>0)
{
    int my1stPosition=richTextBox1.Find(mystring);
    richTextBox1.SelectionStart=my1stPosition;
    richTextBox1.SelectionLength=mystring.Length; 
    richTextBox1.SelectionFont=fnt;
    richTextBox1.SelectionColor=Color.CadetBlue;
}

答案 2 :(得分:0)

使用标准TextBox是不可能的,您需要使用RichTextbox

然后,看看如何highlight words in a RichTextBox

希望它有所帮助。

相关问题