tags:

views:

66

answers:

3

Hi all How 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.

A: 

You do not. Strings have no color. PRESENTATION of strings may have a color, but that is not something you determine in the string.

TomTom
I'm using a WINFORMS and I try to display it in a textbox, I can Use richtextbox as well.
+3  A: 

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);
Albin Sunnanbo
Thanks man,It solved the problem.
A: 

Using the RichTextBox control, check out the tutorial on Syntax Highlighting presented here:

http://www.c-sharpcorner.com/uploadfile/duncanharris/syntaxhighlightinrichtextboxp112012005050840am/syntaxhighlightinrichtextboxp1.aspx

djacobson