Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


.NET Windows Form RichTextBox append text causes color inconsistency

Posted on 2009-05-08
Medium Priority
Last Modified: 2013-12-17
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

Question by:transcend3nt
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 86

Accepted Solution

Mike Tomlinson earned 375 total points
ID: 24336361
Before setting SelectionFont and SelectionColor you need to make sure that the cursor is at the END of your RichTextBox (it could be moved by the user or possibly thru other code):

            richtextbox.SelectionStart = richtextbox.TextLength; // move cursor to the END first!
            richtextbox.SelectionFont = fontFromFontDialog;
            richtextbox.SelectionColor = colorFromColorDialog;
            richtextbox.AppendText("Some text");
            // (just FYI) alternative to AppendText():
            richtextbox.SelectedText = "Some text";

Open in new window


Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question