Как изменить цвет фона определенной строки в RichTextbox?
Код: Выделить всё
public async Task AddMessage(string message,Color background)
{
int start = RichTextBox.TextLength;
RichTextBox.AppendText(message + "\n");
int end = RichTextBox.TextLength;
// Select the entire line, including the trailing whitespace after the text
RichTextBox.Select(start, end - start + 1);
RichTextBox.SelectionBackColor = userBackground; // Set background color for the entire line
RichTextBox.SelectionLength = 0; // Reset selection
await Task.Run(() => RichTextBox.Invoke((MethodInvoker)(() => RichTextBox.Refresh())));
}
< /code>
И я использую его таким образом: < /p>
public async Task test()
{
for (int i = 0; i < 10; i++)
{
await AddMessage($"Blue{i}", Color.LightBlue);
await AddMessage($"Green{i}", Color.LightGreen);
}
}
Что не так с моим кодом и как я могу его исправить? /> < /p>
Подробнее здесь: https://stackoverflow.com/questions/796 ... in-winform