string aa="abcdefghijk"; //一个字符串string bb="efg";         //要改变颜色的字符串richTextBox1.Text="abcd (红色开始)efg(红色结束)hijk";

解决方案 »

  1.   

    richTextBox1.Select(Start, length);
    richTextBox1.SelectionColor = Color.Red;
      

  2.   

    richTextBox是支持html的代码的,用font标签加上color就可以了。
      

  3.   

    用replace给替换成efg加上<font  color='red'>efg</font>
      

  4.   

    Font f=new Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point);
    string str="";
    if (richTextBox1.Find(str)>0)
    {
    int pos=richTextBox1.Find(str);
    richTextBox1.SelectionStart=pos;
    richTextBox1.SelectionLength=str.Length;   
    richTextBox1.SelectionFont=f;
    richTextBox1.SelectionColor=Color.Red;
    }   
      

  5.   

    可以用JS的代码来写 用声明变量的方法来写 
    或者用hyperlink来写 在属性里面的"style"来改
      

  6.   

    Font f=new Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point);
    string str="";
    if (richTextBox1.Find(str)>0)
    {
    int pos=richTextBox1.Find(str);
    richTextBox1.SelectionStart=pos;
    richTextBox1.SelectionLength=str.Length;   
    richTextBox1.SelectionFont=f;
    richTextBox1.SelectionColor=Color.Red;
    }   
      

  7.   


       //设置第4个字符开始长度为2的字符串颜色为红色
                this.richTextBox1.Select(3, 2);
                this.richTextBox1.SelectionColor = System.Drawing.Color.Red;
                //设置第6个字符开始长度为3的字符串颜色为蓝色
                this.richTextBox1.Select(5, 3);
                this.richTextBox1.SelectionColor = System.Drawing.Color.Blue;