所要实现的功能是有点类似在线编辑器,有一个文本框,当选中文本框其中的文字时,单击一个按钮,文本框中被选中文字的两旁出现字符串。截图所示 
单击按钮前单击按钮后

解决方案 »

  1.   

                textBox1.SelectedText = "<font color=red>" + textBox1.SelectedText + "</font>";
      

  2.   

    string s1 = textBox1.Text;
    string s2 = textBox1.SelectedText;
    string s3 = s1.Substring(0, s1.IndexOf(s2)) + "<font color = red>" + s2 + "</font >"+s1.Substring(s1.IndexOf(s2) + s2.Length);
    试试吧
      

  3.   

    textBox1.SelectedText = "<font color=red>" + textBox1.SelectedText + "</font>";
      

  4.   


    winform的textbox有SelectedText属性。。
    web的是没有的