c# - RichTextBox - Add text to top with multiple colors (only latest line is showing) -


i'm trying replicate log window, recent log should appear @ top - visible. thus, need add text top (no problem) multiple colors (problem).

first store original text. (it's rtf or text - tried both) , add new text, username , message. username should 1 color , message another. it's single lined too.

all method when appending old text or old rtf text, latest "log" 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 possible? because doesn't save old rtf text , old rtf text can't appended after new text, means have add newest text below isn't want.

if instead of saving "rtf" text, format (colors) disappear , show 1 color.

not tested 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 { } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -