开发者

How to Change text color?

Hi I am using following code to append text and I want to change the color of 开发者_如何学运维newly appended text how is it possible

if (strMessage.IndexOf("pvt|") == -1)
{
   string[] temp = strMessage.Split(new string[] {"&^:^&"}, tringSplitOptions.None);
   strMessage = temp[0] + "(" + DateTime.Now.ToString("HH:mm tt") + ")" + ":" + emp[1];
   txtLog.AppendText(strMessage + "\r\n");
}

Please help..


Where is the text being displayed? It appears that it goes to a TextBox, but that's just an assumption.

Changing the color of individual chunks of text within a normal TextBox is not possible. You can change the entire TextBox's forecolor by setting its ForeColor property.

txtLog.ForeColor = Color.Red;

To change pieces of it individually, then you will need to use a different textbox, such as shown in the answer here.


Assuming that txtLog is a text file you would have to encode ascii control characters into stream and have an editor that read them. This link might help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜