Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:47:28+00:00 2026-05-29T15:47:28+00:00

I put some colored text to my rich text box my using the following

  • 0

I put some colored text to my rich text box my using the following code:

richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = "Name";
richTextBox1.SelectionColor = Color.Black;
richTextBox1.SelectedText = ": some message.";

But when I hide the richtextbox from the user by setting its parent property to null (I have this panel that holds different rich text boxes from time to time), and put it back, the rich text box does not retain the text colors I applied to it. All texts becomes black.

Update: I tried an experiment. In my main program, I have a UserControl (which has a Panel) where I put a RichTextBox with colored text. I have many RichTextBoxes which I store to a HashTable.

So when I need a RichTextBox, I retrieve it from my HashTable, put some colored text into it, put it inside my UserControl’s Panel and finally put my UserControl to my program’s Form. My UserControl can actually be temporarily removed from the program’s Form when a user clicks on a button, I do using Controls.Remove(). To put it back into my Form, I use Controls.Add(). The problem is, when the UserControl is added back, the RichTextBox’s texts are not colored anymore.

I tried doing something similar in another experimental program.

public partial class Form1 : Form
{

private chat.UserControl1 ChatWindowKuno = new chat.UserControl1();
private Hashtable htChatLogs = new Hashtable(30);

public Form1()
{
    InitializeComponent();
    createRTBox();
}

private void createRTBox()
{
    RichTextBox richTextBox1 = new RichTextBox();
    richTextBox1.Multiline = true;
    richTextBox1.Dock = DockStyle.Fill;
    richTextBox1.ReadOnly = true;
    richTextBox1.BackColor = SystemColors.Window;
    htChatLogs.Add("Basta", richTextBox1);
}        

private void button1_Click_1(object sender, EventArgs e)
{
    if (ChatWindowKuno.Parent == null)
        ChatWindowKuno.Parent = tabPage2;
    else
        ChatWindowKuno.Parent = null;
}

private void button2_Click(object sender, EventArgs e)
{
    // Clear all text from the RichTextBox;

    RichTextBox richTextBox1 = (RichTextBox)htChatLogs["Basta"]; 

    richTextBox1.Clear();

    richTextBox1.SelectionFont = new Font("Segoe UI", 8.25F, FontStyle.Regular);
    richTextBox1.SelectionColor = Color.Blue;
    richTextBox1.SelectedText = "Xel";
    richTextBox1.SelectionColor = Color.Black;
    richTextBox1.SelectedText = ": Listening to Be My Last by Utada Hikaru.";
    richTextBox1.SelectionColor = Color.Gray;
    richTextBox1.SelectionFont = new Font("Segoe UI", 8.25F, FontStyle.Italic);
    richTextBox1.SelectedText = " [5:56pm] \n";

    richTextBox1.SelectionColor = Color.Gray;
    richTextBox1.SelectedText = "[5:56pm] ";
    richTextBox1.SelectionFont = new Font("Segoe UI", 8.25F, FontStyle.Regular);
    richTextBox1.SelectionColor = Color.Blue;
    richTextBox1.SelectedText = "Xel";
    richTextBox1.SelectionColor = Color.Black;
    richTextBox1.SelectedText = ": Listening to Be My Last by Utada Hikaru.";

}

private void button3_Click(object sender, EventArgs e)
{
    RichTextBox richTextBox1 = (RichTextBox)htChatLogs["Basta"];
    ChatWindowKuno.ChatLog = richTextBox1;
}
}  

The ChatLog property of usercontrol1 is this:

    public Control ChatLogPanel
    {
        get
        {
            return panel1.Controls[0];
        }
        set
        {
            panel1.Controls.Clear();
            panel1.Controls.Add(value);
        }
    }

I click the 3 buttons randomly in my experimental program, but the text colors are retained.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:47:28+00:00Added an answer on May 29, 2026 at 3:47 pm

    You shouldn’t use Parent property to hide, but Visible property instead.

    If you hide a richtextbox using richTextBox.Visible = false it keeps its formatting (tested).

    EDIT :

    as discussed in the comments below, I suggest you to use only one RichTextBox and store several Rtf strings in a Dictionary (or Hashtable) to mimic the existence of different RichTextBox‘es.

    An example of what I mean can be found Here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to put some plain text in the iPhone Pasteboard. The following code
The following jQuery example should put some text into the div, but it doesn't.
i have put in a css box colored red and for some reason the
I am trying to put some distributed caching into play, I'm using this indeXus.Net
I wish to put some text on a page and hide some data in
I put some debugging messages in the kernel code. have checked /var/log/messages, dmesg and
Sometimes we put some debug prints in our code this way printf(successfully reached at
I'm trying to put some text inside an input, tried this: $(#someText).click(function () {
How can I put some text into a TextBox which will be removed automatically
I need to put some subtext in a Winforms C# labels .Text property. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.