在WINFORM中如果实现 鼠标选中一行文字中的一小段儿文字  然后提取出来?如何实现关键字变色?假如我在TEXTBOX里输入一行文字。当里面有Csdn的时候  我就让他显示为蓝色。 如果有.NET 我就让他显示为红色。

解决方案 »

  1.   

    在你的form里面 好办你可以用RichTextBox 来显示问题 判断用户选中 文字 将文字属性设置为 某种颜色如果为CSDn 的话  用正则判断   
      

  2.   

    参考
    http://www.aspx2.com/a/WinForm/2010/0528/42360.html
      

  3.   

    SendTxtMessage(hwdText, WM_SETTEXT, 0, strText.ToCharArray());
    IDataObject iData = Clipboard.GetDataObject();
    if (null != iData)
    {
         if (iData.GetDataPresent(DataFormats.Text))) 
          {
              selectedText += (String)iData.GetData(DataFormats.Text);
         } 
    }int index = richTextBox1.Text.IndexOf('\n', start);
    while (index > -1)
    {
      richTextBox1.Select(start, index - start);
      setColor(count);
      count++;
      start = index + 1;
      index = richTextBox1.Text.IndexOf('\n', start);
    }
    private void setColor(int lines)
    {
      richTextBox1.SelectionColor = Color.Blue;
    }
      

  4.   

    参考这里的源代码就可以了。
    注意要先注册为codeproject网站的用户,只需要一个邮箱地址就可以注册了,挺方便的,而且上面有很多好歹么。RichTextBox with background highlighting in VB.NET
      

  5.   

    richTextBox1.SelectionColor = 你所设定的颜色
      

  6.   

    richTextBox1.Select(startIndex, length);
    richTextBox1.SelectionColor = color;
      

  7.   

    如果实现 鼠标选中一行文字中的一小段儿文字 然后提取出来?
    How to Realize it
      

  8.   

    恩codeproject上有不少这样的例子不过也可以简单点,直接使用现成的控件,比如QWhale.Editor控件