private void richTextBox1_SelectionChanged(object sender, EventArgs e)
{
pos = richTextBox1.SelectionStart;
}
private int pos = 0;
private string str;
private void btnFindNext_Click(object sender, EventArgs e)
{
str = textBox1.Text;
pos = richTextBox1.Find(str, 0, pos, RichTextBoxFinds.Reverse);
if (pos == -1)
MessageBox.Show("无结果!");
}int nEnd 控件文本中结束搜索的位置。让这个数值小于richTextBox1.TextLength就能实现搜索上一个的字符串
public int Find(string str, int start, int end, RichTextBoxFinds options);
//
// 摘要:
// 在对搜索应用特定选项的情况下,在 System.Windows.Forms.RichTextBox 控件文本中搜索控件内某个文本范围内的字符串。
//
// 参数:
// str:
// 要在控件中定位的文本。
//
// start:
//
// end:
// 控件文本中结束搜索的位置。此值必须等于 -1 或者大于或等于 start 参数。
//
// options:
// System.Windows.Forms.RichTextBoxFinds 值的按位组合。
//
// 返回结果:
// 控件内找到搜索文本的位置。
//
// 异常:
// System.ArgumentNullException:
// str 参数为 null。
//
// System.ArgumentException:
// start 参数小于零。
//
// System.ArgumentException:
// end 参数小于 start 参数。