string s;
s.IndexOf(?);
用这个函数,可以处理,然后大概用TextBox的Select??();一个函数就可以搞定了,我前不久才做过,文本查找.

解决方案 »

  1.   

    之前写了一个查找下一个的函数,搂主可以直接调用:
    private int FindNext(string text, bool bMatchCase, bool bReverse)
    {
        if (text == null) return -1;    this.richTextBox1.Focus();    RichTextBoxFinds findOptions = RichTextBoxFinds.None;    int start = this.richTextBox1.SelectionStart;
        int end = start;    if (bReverse)
        {
            start = 0;
            end = this.richTextBox1.SelectionStart;
            findOptions |= RichTextBoxFinds.Reverse;
        }
        else
        {
            start += this.richTextBox1.SelectionLength;
            end = this.richTextBox1.TextLength;
            this.richTextBox1.SelectionStart = start;
        }
        this.richTextBox1.SelectionLength = 0;    if (bMatchCase)
        {
            findOptions |= RichTextBoxFinds.MatchCase;
        }
        return this.richTextBox1.Find(text, start, end, findOptions);
    }text-将要被查找的文本;bMatchCase-是否区分大小写;bReverse-是否反向查找
      

  2.   

    自动换行直接使用this.richTextBox1.WordWrap = true或者false就可以实现了
      

  3.   

    用richTextBox写记事本吧,很方便,微软都帮你
    想好了,好多都封装好了,连赊销返回都给你了。
    Undo(),Redo();
      

  4.   

    我用的就是richTextBox  就是出现这个错误
    //查找
    private void menuItemFind_Click(object sender, System.EventArgs e)
    {
    new Find(txtResult).Show(); 
    } //查找下一个
    private void menuItemFindNext_Click(object sender, System.EventArgs e)
    {
    new Replace(txtResult).Show();
    }出现的错误是:找不到类型或者命名空间名称“Find”(是否缺少using指令或程序集引用)
                  找不到类型或者命名空间名称“Replace”(是否缺少using指令或程序集引用)
      

  5.   


    private void menuItemFind_Click(object sender, System.EventArgs e)
            {
                (new Find(txtResult)).Show(); 
            }        //查找下一个
            private void menuItemFindNext_Click(object sender, System.EventArgs e)
            {
                (new Replace(txtResult)).Show();
            }
      

  6.   

    晕,我8楼的代码仅仅是修正你在7楼贴出的代码,但我并不知道find和replace两个窗口类是怎么实现的,所以就没有再多说find和replace两个窗口类,内部的查找和替换方法,见我在2楼贴出的代码,你可以调用的
      

  7.   

    晕,我8楼的代码仅仅是修正你在7楼贴出的代码,但我并不知道你的find和replace这两个窗口类是怎么实现的,所以就没有再多说 find和replace两个窗口类,内部的查找和替换方法,见我在2楼贴出的代码,你可以调用的 
      

  8.   

    不用,new优先级比.要高,,可以不加括号…………查找、查找下一个都调用同一个方法 FindString()public class Notepad
    {
        private string p_find;
        ...
        private void FindString()
        {
            if (p_find == null || p_find.Length == 0)
            {
                // 在这打开一个对话框获得一个要查找的字符串
                p_find = ......
                if (p_find == null || p_find.Length == 0)
                    return;
            }
            textBox1.SelectionStart = textBox1.Text.IndexOf(p_find, textBox1.SelectionStart);
            textBox1.SelectionLength = p_find.Length;
        }
    }
      

  9.   

    搂主可以下载下面我专门针对文本编辑器软件写的查找和替换功能代码:
    http://download.csdn.net/source/894891
    该功能已经做得很完善,可以参考
      

  10.   

    这里做个一个记事本(带原代码),可以参考一下
    http://www.popuni.com/article.asp?id=96
    还是比较简单的