Nejc Trstenjak
Nejc Trstenjak

Reputation: 43

Changing Font Color RTF

foreach (Color b in new ColorConverter().GetStandardValues())
{
   RichTextBox rtf = new RichTextBox();
   string[] s = rtf.Lines;

   richTextBox1.Text += b.ToString() + s.ToString() + "\r\n";
   button1.BackColor = b;
   Application.DoEvents();
   Thread.Sleep(10);        
}

Greetings everyone,

I have a sequence going through all the KnownColors, changing the button's color and writing the name of each color in the RTF, each in it's own line. Now I wish to change the font color of each line to match the name of the color in each line.

Cheers, N

Upvotes: 1

Views: 1571

Answers (2)

Idle_Mind
Idle_Mind

Reputation: 39132

Try this out...

        richTextBox1.Clear();
        foreach (Color b in new ColorConverter().GetStandardValues())
        {
            richTextBox1.SelectionStart = richTextBox1.TextLength;
            richTextBox1.SelectionColor = b;
            richTextBox1.SelectedText = b.ToString() + "\r\n";
            button1.BackColor = b;
            Application.DoEvents();
            Thread.Sleep(10);
        }

Upvotes: 2

deathismyfriend
deathismyfriend

Reputation: 2192

try this.

    foreach (Color b in new ColorConverter().GetStandardValues())
    {
       RichTextBox rtf = new RichTextBox();
       string[] s = rtf.Lines;

       richTextBox1.Text += b.ToString() + s.ToString() + "\r\n";
       richTextBox1.SelectionColor = b;
       button1.BackColor = b;
       Application.DoEvents();
       Thread.Sleep(10);        
    }

Upvotes: 0

Related Questions