[c#]代码库
haveSearchedTimes = 0;
string path = System.Environment.CurrentDirectory;
DirectoryInfo di = new DirectoryInfo(path);
foreach (var sdi in di.GetDirectories())
{
foreach (var fi in sdi.GetFiles("*.txt"))
{
var result = Search(fi);
if (!string.IsNullOrEmpty(result))
{
richTextBox1.Clear();
//richTextBox1.SelectionBackColor = Color.White;
//richTextBox1.Select(0, 0);
richTextBox1.Text = result;
int start = -pattern.Length;
for (int i = 0; i < matchTimes; i++)
{
start = richTextBox1.Find(pattern, start + pattern.Length, RichTextBoxFinds.NoHighlight);
}
richTextBox1.Select(start, pattern.Length);
richTextBox1.SelectionBackColor = Color.Red;
return;
}
}
}
[代码运行效果截图]
[源代码打包下载]