如何为RichTextBox创建查找表单? [英] How do I create a Find form for a RichTextBox?

查看:52
本文介绍了如何为RichTextBox创建查找表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能的话,我想向上,向下搜索并匹配大小写.甚至可以帮助我入门的链接.

I would want to search up, down, and match case if possible. Even links to get me started would be appreciated.

推荐答案

不确定向上搜索,但就发现可以使用类似的东西

Not sure about the up searching but as far as finding you can use something like this

int selStart = ControltoSearch.SelectionStart;
int selLength = ControltoSearch.SelectionLength;
int newLength = SearchFor.Length;

int newStart = searchIn.IndexOf(SearchFor, selStart + selLength, compareType);

ControltoSearch.SelectionStart = newStart >= 0 ? newStart : 0;
ControltoSearch.SelectionLength = newLength;
ControltoSearch.ScrollToCaret();
ControltoSearch.Focus();

return newStart;

对于匹配的大小写,您可以在文本搜索和文本搜索中同时使用String.ToLowerInvariant(),否则String.Contains()区分大小写

For matched case you can use String.ToLowerInvariant() on both the search in text and the search for text otherwise String.Contains() is case sensitive

searchIn.ToLowerInvariant().Contains(SearchFor.ToLowerInvariant())

这篇关于如何为RichTextBox创建查找表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆