Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
Am working on RichTextBox in WPF. I placed a tool bar which is above to the richtextbox. that toolbar consists of Bold,Italic,UnderLine,Left,Center,Right,ColorDialog etc.
Everything is workinfg fine. But the problem here is,
if i change the font size to 24, make it bold and then Center it.
Now highlight it and change the color to red. The justification will change to Left, eventhough Centered is still highlighted.


How to maintain the status of current text alignment here? Even though i change the color of text using colordialog,the alignment of the should remain same. It should not move to Left.
Plz anyone help me onthis asap.
thank you,
Regards,
Santhosh
Posted
Updated 13-Sep-10 20:38pm
v2

Are you doing

richtextbox.SelectionColor = Color.Red;

I think somehow the richtextbox is modifying the SelectionFont to its default when you change its color.

Check your code minutely, it should be working I think.
 
Share this answer
 
Comments
Sandeep Mewara 14-Sep-10 5:05am    
Comment from OP:
Hai Abhishek Sur,
Am using code like below.

System.Drawing.Color SelectedColor = ColorDialog1.Color;
string color1 = ColorDialog1.Color.ToString();
System.Windows.Media.BrushConverter bc = new System.Windows.Media.BrushConverter();
System.Windows.Media.Brush b1 = (System.Windows.Media.Brush)bc.ConvertFromString(ToHtml(SelectedColor));
TextRange range = new TextRange(rtbDescription.Selection.Start, rtbDescription.Selection.End);
range.ApplyPropertyValue(FlowDocument.ForegroundProperty, b1);

No whenever am changing the color for the text in richtextbox, the font is not effecting. Everything working fine.
In one WPF Window, i have 3 richtext boxes, all of these three having the toolbars respectively. The same thing is working fine in all specifications in another window where am having only one richtextbox with respective toolbox also
you need to use

range.ApplyPropertyValue(TextElement.ForegroundProperty, b1);
 
Share this answer
 
you need to use

range.ApplyPropertyValue(TextElement.ForegroundProperty, b1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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