Link to home
Start Free TrialLog in
Avatar of transcend3nt
transcend3nt

asked on

.NET Windows Form RichTextBox append text causes color inconsistency

This is a very unique problem I am facing.

In .NET 2.0, if you want to append formatted text (with font styles/color) into a rich textbox, you use this code :


richtextbox.SelectionFont = fontFromFontDialog;
richtextbox.SelectionColor = colorFromColorDialog;
richtextbox.AppendText("Some text");


the font and color are obtained from a color and font dialog.

For the first few times, the colors are correct. however if i keep changing font and colors, the colors get mixed up. If i select orange, it might appear blue on the richtextbox.

Anyone can give a solution? Really surprusing..


richtextbox.SelectionFont = fontFromFontDialog;
richtextbox.SelectionColor = colorFromColorDialog;
richtextbox.AppendText("Some text");
 
// keep looping this with different colors/fonts will give wrong colors

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial