if (counter == 0)
textBox2.Text += "ERROR: the item in the " + j + "th row is wrong" + Environment.NewLine;
如何在TextBox中顯示j變量紅色?如何打印彩色文字
if (counter == 0)
textBox2.Text += "ERROR: the item in the " + j + "th row is wrong" + Environment.NewLine;
如何在TextBox中顯示j變量紅色?如何打印彩色文字
你可以改變整個字體的顏色。使用textBox2.ForeColor = Color.Red
或者使用RichTextBox
首先,使它成爲一個豐富的文本框,而不是一個普通文本框。
然後
Font fnt=new Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point);
string [email protected]" " + 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;
}
對不起,隊友,但它不工作。 –
嗯,也許你確實修復了搜索字符串('mystring')。或者可能不是 – sehe
我把它做成了'string mystring = @「」+ j + 1 +「th」;'對嗎? –
可能的重複:http://stackoverflow.com/questions/2813522/how-to-change-the-font-color-in-the-textbox-in-c – Peter
簡單的答案:使用RichTextBox http:// msdn .microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx – Peter
如果這是ASP.NET,您可以使用驗證程序來實現此目的,它顯示紅色的文本 – sll