asp.net中RichTextBox控件添加指定颜色文本例子

作者:袖梨 2022-06-25

asp.net中RichTextBox控件添加指定颜色文本例子

 代码如下 复制代码


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; //取消选中
}

相关文章

精彩推荐