日期:2014-05-17  浏览次数:20767 次

richTextBox控件的find四参方法,看看吧,不要一分钟,分数轻松拿,熟悉使用的请进!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Winform1
{
    public partial class 富文本框 : Form
    {
        public 富文本框()
        {
            InitializeComponent();
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            int start;
            int end;
            start = rchContent.SelectionStart;
            end = rchContent.Text.Length;
            int index = FindMyText("中国", start, end);
            if (index != -1)
            {

                MessageBox.Show(string .Format("查找成功!{0},{1},{2}",start,end,index ) );
                rchContent.Select(index ,2);
                rchContent.Focus();

            }
            else
            {
                MessageBox.Show(string .Format("查找失败!{0},{1},{2}",start,end,index  ));
            }                       
        }
问题:如富文本框中的内容为“我爱你中国”为什么当光标在最后时,即start在最后时,还能找到?就好像每次都是从头找,而不是从start开始找。
------解决方案--------------------
补充:准备工作:建立一个windows应用程序,拉一个richTextBox,name=rchContent,一个Button按钮,name=btnFind,然后将代码复制粘贴即可。
------解决方案--------------------
天知道 FindMyText 是怎么写的。

不过你可以用 string.IndexOf 函数。