c#实现richtextbox的查找
1个回答
展开全部
internal void FindText(RichTextBox rtb, string text)
{
rtb.HideSelection = false;
int searchStartPosition = rtb.SelectionStart;
if (rtb.SelectedText.Length > 0)
{
searchStartPosition = rtb.SelectionStart + rtb.SelectedText.Length;
}
int indexOfText = rtb.Find(text, searchStartPosition, RichTextBoxFinds.None);
if (indexOfText >= 0)
{
searchStartPosition = indexOfText + rtb.SelectionLength;
rtb.Select(indexOfText, rtb.SelectionLength);
}
else
{
MessageBox.Show(String.Format("找不到“{0}”...", text));
}
}
然后你用一个子窗体回调这个方法就行了
{
rtb.HideSelection = false;
int searchStartPosition = rtb.SelectionStart;
if (rtb.SelectedText.Length > 0)
{
searchStartPosition = rtb.SelectionStart + rtb.SelectedText.Length;
}
int indexOfText = rtb.Find(text, searchStartPosition, RichTextBoxFinds.None);
if (indexOfText >= 0)
{
searchStartPosition = indexOfText + rtb.SelectionLength;
rtb.Select(indexOfText, rtb.SelectionLength);
}
else
{
MessageBox.Show(String.Format("找不到“{0}”...", text));
}
}
然后你用一个子窗体回调这个方法就行了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询