Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hey guys

I need to append text to a WPF RichTextBox, but specific colors.

After much googling i put together the following method

private void AppendRtfText(string Text, Brush Color)<br />{<br />    TextRange range = new TextRange(txtChat.Document.ContentEnd, txtChat.Document.ContentEnd);<br />    range.Text = Text;<br />    range.ApplyPropertyValue(TextElement.ForegroundProperty, Color);<br />}


Now this works just fine, but I need to be able to specify RGB values.

The TextElement.ForegroundProperty only accepts a Brush and as far as I can see I cant specify RGB for a brush like i would with the Color class.

Any ideas? Cause I'm running out

Posted

1 solution

Taken from http://msdn.microsoft.com/en-us/library/system.windows.media.brushes(VS.85).aspx[^]

<br />SolidColorBrush mySolidColorBrush = new SolidColorBrush();<br /><br />// Describes the brush's color using RGB values. <br />// Each value has a range of 0-255.<br />mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255);<br />



hth, Philipp

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900