tags:

views:

59

answers:

2

I have TextBlock in my main form. I set the Text property to different strings during the application run.

I would like to be able to colour parts of particular strings.

Say (pseudo-code)

if(a < 0) txbStatus.Text = string.Format("{0} <RED>{1}</RED>",  a, b);
     else txbStatus.Text = string.Format("{0} <BLUE>{1}</RED>", a, b);
+3  A: 

The content of a TextBox doesn't have to be just a string, but a collection of Inlines:

txbStatus.Inlines.Clear();
txbStatus.Inlines.Add(new Run("normal color, "));
txbStatus.Inlines.Add(new Run("colored text") { Foreground = Brushes.Red });
svick
+3  A: 

You can split your string the way u want and then using a foreach() loop for that split string try

TextBlockName.Inlines.Add(new Run("colored text")) {Foreground = Brushes.Blue});
Johnny
works perfectly. thanks ! (there is one extra bracket though)
Bobb
Oops sorry for that extra bracket....
Johnny