richtextbox 里面有内容   在里面查询某个字符串,查询到就选定该字符串  如何实现? 

解决方案 »

  1.   

    查找就string。find 选定不知道
      

  2.   

    int i=richTextBox1.Text.IndexOf("123");
                richTextBox1.Select(i,3);
      

  3.   


    public void SelectMyString()
     {
        // Create a string to search for the word "fox".
        String searchString = "fox";
        // Determine the starting location of the word "fox".
        int index = textBox1.Text.IndexOf(searchString, 16, 3);
        // Determine if the word has been found and select it if it was.
        if (index != -1)
        {
           // Select the string using the index and the length of the string.
           textBox1.Select(index, searchString.Length);
        }
     }这是MSDN上提供的方法。
      

  4.   

    int i=richTextBox1.Text.IndexOf("123");
                richTextBox1.Select(i,3);
    查找到的是第一个,如果我想让他继续找第二个,怎么办
    我要放个按钮上去,点下一个就去找下一个了。
      

  5.   

    你的能找到吗?
    怎么我的找不到?
            private void button2_Click(object sender, EventArgs e)
            {
                int i = richTextBox1.Text.IndexOf("123");
                richTextBox1.Select(i, 3);
            }
      

  6.   

    囧 原来是焦点的问题
    加了个
    richTextBox1.Focus();
    就解决了
      

  7.   

    string s="";
    int index = this.richTextBox1.Find(s);
    if (index < 0)
    {
        MessageBox.Show("查找不到");
        return;
    }
    this.richTextBox1.SelectionStart = index;
    this.richTextBox1.SelectionLength = s.Length;
    this.richTextBox1.Focus();
      

  8.   

                string m = richTextBox1.Text.Substring(iii, richTextBox1.Text.Length - iii);
                int j = m.IndexOf("123");
                if (j >= iii)
                {
                    iii += j;                MessageBox.Show(iii.ToString());
                    richTextBox1.Select(iii, 3);
                    richTextBox1.Focus();            }
                else(Messagebox.show("查找不到"+"123"));
                iii++;
    这个我写的 刚才试了下 可以查找下一个,最好在光标改变的时候把iii清0;
      

  9.   

    string m = richTextBox1.Text.Substring(iii, richTextBox1.Text.Length - iii);
                int j = m.IndexOf("123");
                if (j >=0)
                {
                    iii += j;                MessageBox.Show(iii.ToString());
                    richTextBox1.Select(iii, 3);
                    richTextBox1.Focus();
                    iii += 3;            }
                else
                    MessageBox.Show("不能找到");
    这个好了 
    刚才那个有问题
      

  10.   

    iii 是什么,代码不完整 迷茫了