how to change color of an text in richtextbox in wpf

Posted by Sudhakar_A under C# on 10/14/2013 | Points: 10 | Views : 6518 | Status : [Member] | Replies : 2
i use delegates to update ma richtextbox text as

richTextBox1.Dispatcher.Invoke( new UpdateTextCallback(this.UpdateText),new object[] { outputofvalidation });
richTextBox1.Dispatcher.Invoke(new UpdateTextCallback(this.UpdateText),new object[] {output});
richTextBox1.Dispatcher.Invoke(new UpdateTextCallback(this.UpdateText),new object[]{"Device is connected successfully"});

The above three text are appended together in ma richtextbox.
i wan to display all the three text in different colors.

pls help me to sort out




Responses

Posted by: Bandi on: 10/15/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://stackoverflow.com/questions/5442067/change-color-and-font-for-some-part-of-text-in-wpf-c-sharp
http://stackoverflow.com/questions/1926264/color-different-parts-of-a-richtextbox-string
http://stackoverflow.com/questions/17175694/wpf-richtextbox-change-font-color-inline
http://www.codeproject.com/Questions/41607/WPF-RichTextBox-Appending-Colored-text

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samirbhogayta on: 10/15/2013 [Member] Starter | Points: 25

Up
0
Down
<RichTextBox x:Name="yourRichTextBox" TextChanged="yourRichTextBox_TextChanged_1">
<FlowDocument>
<Paragraph>
<Run Text="fdsfdfsda"/>
</Paragraph>
<Paragraph>
<Run/>
</Paragraph>
</FlowDocument>
</RichTextBox>

Code Behind:
private void yourRichTextBox_TextChanged_1(object sender, TextChangedEventArgs e)
{
yourRichTextBox.Selection.ApplyPropertyValue(RichTextBox.ForegroundProperty, Brushes.Red);
}

SAMIR
Sr. Software Engineer

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response