change the color of a char
How c开发者_如何学Can I change the color of a char in a string using C#? for ex. MIND, make D to be red and the rest remain black.
I'm using a WINFORMS and I try to display it in a textbox, I can Use richtextbox as well.
You can do that with a RichTextBox at least.
// Save selection
var oldStart = richTextBox1.SelectionStart;
var oldLength = richTextBox1.SelectionLength;
// Select the text to change
richTextBox1.Select(richTextBox1.TextLength - 1, 1);
// Change color
richTextBox1.SelectionColor = Color.Red;
// Restore selection
richTextBox1.Select(oldStart, oldLength);
You do not. Strings have no color. PRESENTATION of strings may have a color, but that is not something you determine in the string.
Using the RichTextBox control, check out the tutorial on Syntax Highlighting presented here:
http://www.c-sharpcorner.com/uploadfile/duncanharris/syntaxhighlightinrichtextboxp112012005050840am/syntaxhighlightinrichtextboxp1.aspx
精彩评论