![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
private
int
FindPlace
=
0
;
//
文本查找位置,缺省为文本起点
2 private void btnStart_Click( object sender, EventArgs e)
3 {
4 if (txtToSearch.Text != "" ) // 当查找内容不为空时,进行查找
5 {
6 // 获得Form1窗体的引用
7 MainForm mainForm = (MainForm) this .Owner;
8 // 如果主窗体文本内容不为空,进行查找
9 if (mainForm.rtbData.Text.Length > 0 )
10 {
11 if ((FindPlace = mainForm.rtbData.Text.IndexOf(txtToSearch.Text, FindPlace)) == - 1 )
12 {
13 MessageBox.Show( " 没有搜索到! " );
14 FindPlace = 0 ; // 没有找到,重置查找位置为文本起点
15 }
16 else
17 { // 选中找到的文本,使其明显
18 mainForm.rtbData.Select(FindPlace, txtToSearch.Text.Length);
19 // 找到了,置查找位置为下一个位置
20 FindPlace = FindPlace + txtToSearch.Text.Length;
21 mainForm.Focus();
22 mainForm.Activate();
23 }
24 }
25 }
26 }
2 private void btnStart_Click( object sender, EventArgs e)
3 {
4 if (txtToSearch.Text != "" ) // 当查找内容不为空时,进行查找
5 {
6 // 获得Form1窗体的引用
7 MainForm mainForm = (MainForm) this .Owner;
8 // 如果主窗体文本内容不为空,进行查找
9 if (mainForm.rtbData.Text.Length > 0 )
10 {
11 if ((FindPlace = mainForm.rtbData.Text.IndexOf(txtToSearch.Text, FindPlace)) == - 1 )
12 {
13 MessageBox.Show( " 没有搜索到! " );
14 FindPlace = 0 ; // 没有找到,重置查找位置为文本起点
15 }
16 else
17 { // 选中找到的文本,使其明显
18 mainForm.rtbData.Select(FindPlace, txtToSearch.Text.Length);
19 // 找到了,置查找位置为下一个位置
20 FindPlace = FindPlace + txtToSearch.Text.Length;
21 mainForm.Focus();
22 mainForm.Activate();
23 }
24 }
25 }
26 }