---
title: "RichTextBox - Add text to top with multiple colors (only latest line is showing)"  
description: "RichTextBox - Add text to top with multiple colors (only latest line is showing)"  
author: "marcel ethan"  
published: 2013-09-04  
updated: 2013-09-04  
canonical: https://www.mindstick.com/forum/1450/richtextbox-add-text-to-top-with-multiple-colors-only-latest-line-is-showing  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# RichTextBox - Add text to top with multiple colors (only latest line is showing)

I'm trying to replicate a log [window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript), so the most recent log should appear at the top - most visible. Thus, I need to add a text to the top (no [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic)) but with [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) [colors](https://answers.mindstick.com/qa/31019/should-i-paint-my-interior-with-neutral-or-bright-colors) (problem).

First I store the original text. (it's rtf or text - tried both) And then I add the new text, with a [username](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username) and then a [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net). The username should be one color and the message another. It's always single lined too.

All I get by my [method](https://www.mindstick.com/forum/166/webservice-method) is that when appending the old text or the old RTF text, the [latest](https://www.mindstick.com/forum/159680/how-can-i-install-the-latest-version-of-sql-server) "log" only shows.

```
public void AddLog(Log log){        try        {            string oldText = this.richTextBox1.Rtf;            this.richTextBox1.Text = log.User + ": " + log.Message + "\n";            this.richTextBox1.Select(0, log.User.Length);            this.richTextBox1.SelectionColor = Color.GreenYellow;            this.richTextBox1.Select(log.User.Length + 2, log.Message.Length);            this.richTextBox1.SelectionColor = Color.White;            this.richTextBox1.DeselectAll();            this.richTextBox1.Rtf += oldText;        }        catch { }}
```

Is this even possible? Because it doesn't save the old RTF text and the old RTF text can't be appended after the new text, which means I probably have to add newest text below which isn't what I want.

If I instead of [saving](https://www.mindstick.com/blog/11865/guide-to-saving-15-for-retirement) the "RTF" text, the [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) (colors) will disappear and will only show one color.

## Replies

### Reply by Sumit Kesarwani

Hi Marcel,\

Try this

```
public void AddLog(Log log){    try    {       
richTextBox1.SelectAll();           
        string oldText
= this.richTextBox1.SelectedRtf;       
this.richTextBox1.Text = log.User + ": " + log.Message +"\n";       
this.richTextBox1.Select(0, log.User.Length);       
this.richTextBox1.SelectionColor = Color.GreenYellow;       
this.richTextBox1.Select(log.User.Length + 2, log.Message.Length);       
this.richTextBox1.SelectionColor = Color.White;       
this.richTextBox1.DeselectAll();       
this.richTextBox1.SelectionStart = this.richTextBox1.TextLength;       
this.richTextBox1.SelectedRtf = oldText;       
this.richTextBox1.DeselectAll();    }    catch { }}
```

\


---

Original Source: https://www.mindstick.com/forum/1450/richtextbox-add-text-to-top-with-multiple-colors-only-latest-line-is-showing

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
