RichTextBox Coloring Problem
-
Hey, this is my problem: i select the last line after i added the new text, i change the color of the line, but then all the lines before becomes the first color inserted and not the color i added them before. what's the problem and how can i fix it? this is the code where i add the text in:
private void rtbAddText(String NewText, Color NewColor) { NewText += Environment.NewLine; if (NewColor == null) this.rtbConsole.Text = NewText; else { int OldLength = rtbConsole.Text.Length; this.rtbConsole.Text += NewText; this.rtbConsole.Select(OldLength, NewText.Length); this.rtbConsole.SelectionColor = NewColor; //this.Select(); //rtbConsole.Select(); } }
Thanks... NaNg. -
Hey, this is my problem: i select the last line after i added the new text, i change the color of the line, but then all the lines before becomes the first color inserted and not the color i added them before. what's the problem and how can i fix it? this is the code where i add the text in:
private void rtbAddText(String NewText, Color NewColor) { NewText += Environment.NewLine; if (NewColor == null) this.rtbConsole.Text = NewText; else { int OldLength = rtbConsole.Text.Length; this.rtbConsole.Text += NewText; this.rtbConsole.Select(OldLength, NewText.Length); this.rtbConsole.SelectionColor = NewColor; //this.Select(); //rtbConsole.Select(); } }
Thanks... NaNg.rather than using
this.rtbConsole.Text += NewText;
you should use
this.rtbConsole.AppendText(NewText);
HTH
-
rather than using
this.rtbConsole.Text += NewText;
you should use
this.rtbConsole.AppendText(NewText);
HTH