Множественный текстовый формат в RichTextBox - PullRequest
0 голосов
/ 13 октября 2011

Предположим, есть две строки.Красная линияСиняя линия.Кто может помочь.

1 Ответ

2 голосов
/ 13 октября 2011

Вы можете использовать:

void AppendText(RichTextBox box, Color color, string text)
{
    int start = box.TextLength;
    box.AppendText(text);
    int end = box.TextLength;

    // Textbox may transform chars, so (end-start) != text.Length
    box.Select(start, end - start + 1);
    box.SelectionColor = color;
    // could set box.SelectionBackColor, box.SelectionFont, etc...
    box.SelectionLength = 0; // clear
}

, а затем

AppendText(rtb, Color.Red, "line1");
AppendText(rtb, Color.Blue, "line2");
...