private void Form1_Load(object sender, EventArgs e)
{
AppendText(richTextBox1, "红", Color.FromArgb(255, 0, 0));
AppendText(richTextBox1, "橙", Color.FromArgb(255, 125, 0));
AppendText(richTextBox1, "黄", Color.FromArgb(255, 255, 0));
AppendText(richTextBox1, "绿", Color.FromArgb(0, 255, 0));
AppendText(richTextBox1, "蓝", Color.FromArgb(0, 0, 255));
AppendText(richTextBox1, "靛", Color.FromArgb(0, 255, 255));
AppendText(richTextBox1, "紫", Color.FromArgb(255, 0, 255));
}
private void AppendText(RichTextBox richTextBox, string str, Color color)
{
richTextBox.AppendText(str);
richTextBox.Find(str, RichTextBoxFinds.Reverse);
richTextBox.SelectionColor = color;
richTextBox.SelectionStart = richTextBox.Text.Length; //取消选中
}
|