Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rich Text Box Color by line

Status
Not open for further replies.
Nov 27, 2006
8
US
I need to be able to change color by line as I add text to a RichTextBox here is the code I have so far.
Code:
private void Updatetext_error(string text)
        {
            Font fBold = new Font("Tahoma", 8, FontStyle.Bold);
            textBox1.SelectionStart = textBox1.Text.Length;
            textBox1.SelectionFont = fBold;
            textBox1.SelectionColor = Color.Red;
            textBox1.SelectedText = text;
            textBox1.SelectionStart = textBox1.Text.Length;
            textBox1.Text += "\r\n Contact your system administrator";
            textBox1.Select(textBox1.Text.Length - 1, textBox1.Text.Length - 1);
            textBox1.ScrollToCaret();

}

if I comment out
Code:
textBox1.Text += "\r\n Contact your system administrator";
then the text is red on the one line that was inserted using the
Code:
textBox1.SelectedText = text;
but if I try to add more text it makes all the text black. Any help would be great.
 
Never mind I found the issue I needed to add \r\n to
Code:
textBox1.SelectedText = text
So it should be
Code:
textBox1.SelectedText = text + "\r\n";
I think what happened was it was still trying to fomrat the selction since there was no new line, or somehting like that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top