分段显示电话号码颜色

Posted on 2019-01-25 23:26  努力成长静待花开  阅读(320)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  RichTextBox控件的Select方法

  public void Select (int start, int length )

  SelectionColor属性

  public Color SelectionColor { get;   set; }

实现代码:

        private void Form1_Load(object sender, EventArgs e)
        {
            this.richTextBox1.Select(0,3);
            this.richTextBox1.SelectionColor = Color.Red;
            this.richTextBox1.Select(3,3);
            this.richTextBox1.SelectionColor = Color.Green;
            this.richTextBox1.Select(6,3);
            this.richTextBox1.SelectionColor = Color.Blue;
            this.richTextBox1.Select(9,3);
            this.richTextBox1.SelectionColor = Color.Brown;
        }