Я хочу иметь цветную Richtextbox, он работает с одной стороны, но если я добавлю другой текст, richtextbox.forcecolor
вернется в белый цвет, и я действительно понятия не имею, почему это происходит. Я пытался сделать что-то вроде richtextbox1.forcecolor = richtextbox1.forcecolor
. Я тоже устал от строк, но ничего не получается.
Вот мой код:
static void HighlightPhrase(RichTextBox box, string phrase, Color color)
{
int pos = box.SelectionStart;
string s = box.Text;
for (int ix = 0; ;)
{
int jx = s.IndexOf(phrase, ix, StringComparison.CurrentCultureIgnoreCase);
if (jx < 0) break;
box.SelectionStart = jx;
box.SelectionLength = phrase.Length;
box.SelectionColor = color;
ix = jx + 1;
}
box.SelectionStart = pos;
box.SelectionLength = 0;
}
if(textBox1.Text == "test")
{
label1.Text = label1.Text + "\n" + DateTime.Now.ToShortTimeString() + " " +"uhh a nice Colored beautiful text :)";
HighlightPhrase(label1, "Colored", Color.Red);
HighlightPhrase(label1, "text", Color.Green);
}
else if (textBox1.Text == "ananas")
{
label1.ForeColor
label1.Text = label1.Text + "\n" + DateTime.Now.ToShortTimeString() + " " + "Why are you dont stay Colored?";
}
Кстати label1
это richtextbox
. А вот и скриншоты.
Цветные:
Не цветные: