更改字体颜色RTF

时间:2013-11-03 17:21:45

标签: c# colors richtextbox

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);        
}

向大家致意,

我有一个序列遍历所有KnownColors,更改按钮的颜色并在RTF中写下每种颜色的名称,每个颜色都在它自己的行中。现在我希望更改每一行的字体颜色以匹配每行中颜色的名称。

干杯,N

2 个答案:

答案 0 :(得分:2)

试试这个......

        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);
        }

答案 1 :(得分:0)

试试这个。

    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);        
    }