我在写记事本查找时遇到了问题 请大家帮帮忙

qilv_7 2012-04-18 06:19:51
private void MenuItemFindNextOne_Click(object sender, EventArgs e)
{
findText = richTextBoxContent.Text;
int start = richTextBoxContent.SelectionStart + richTextBoxContent.SelectionLength;
int end = richTextBoxContent.Text.Length;
if (!string.IsNullOrEmpty(findText))
{
int findIndex = richTextBoxContent.Find(findText, start, end, RichTextBoxFinds.MatchCase);//为什么此处findIndex 总是为-1
if (findIndex == -1)
{
MessageBox.Show("到达文件尾");
}
else
{
richTextBoxContent.Focus();
}
}
}

总感觉还有问题 请大家给完善一下
...全文
72 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveoflife0411 2012-04-19
  • 打赏
  • 举报
回复
int start = richTextBoxContent.SelectionStart + richTextBoxContent.SelectionLength;
int end = richTextBoxContent.Text.Length;
你这的start是不是定义错了?
只需要 int start = richtextBoxContent。SelectionStart;
就可以吧
int findIndex = richTextBoxContent.Find(findText, start, end, RichTextBoxFinds.MatchCase);
要不然 start,end 参数不就不准确了吗?
qilv_7 2012-04-19
  • 打赏
  • 举报
回复
呵呵 我知道那里错了 应该把findText换成findText.SelectText; 晕死
qilv_7 2012-04-19
  • 打赏
  • 举报
回复
start = richTextBoxContent.SelectionStart + richTextBoxContent.SelectionLength 也可以那样写吧
如果没有选中内容的话richTextBoxContent.SelectionLength为0 光标处于0的位置
如果有选中的内容的话,加一下选中内容的长度 并且光标处于则处于start的后面 并且处于下一次查找的开始

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧