Add Colored Text To RichTextBox

Knowledge Base Entry: #55
^Top
<< Back
Mobile-Menu










Add Colored Text To RichTextBox
Category: C-Sharp/Snippets
Author: Bugfish
Created at: 2020-09-24 07:38:02
Modified at: 2025-09-19 21:57:08
Directs Hits: 637

You can add this function to display colored text in a richtextbox! [Just Append With that Function]

        private void AddTextToRTB(RichTextBox rtb, string txt, Color col)
        {
            int pos = rtb.TextLength;
            rtb.AppendText(txt);
            rtb.Select(pos, txt.Length);
            rtb.SelectionColor = col;
            rtb.Select();
            rtb.DeselectAll();
        }

Caution: I do not guarantee the reliability of the information given here, the code described on this page is executed at your own risk and in the event of damage or other unforeseeable consequences I am in no way responsible or liable.
This Website is using Session Cookies for Site Functionality.