C#实现记事本查找功能


 1 private void button1_Click(object sender, EventArgs e)
 2 {
 3     if (!(String.IsNullOrEmpty(this.textBox1.Text)))
 4     {
 5         if (this.richTextBox1.Text.Contains(this.textBox1.Text))
 6         {
 7             int loc = this.richTextBox1.Text.IndexOf(this.textBox1.Text, count + 1);
 8             if (loc == -1)
 9             {
10                 MessageBox.Show("查找结束");
11                 count = -1;
12             }
13             else
14             {
15                 this.richTextBox1.Focus();
16                 this.richTextBox1.Select(loc, this.textBox1.Text.Length);
17                 count = loc;
18             }
19         }
20     }
21 }

注:容易丢失this.richTextBox1.Focus();这段代码


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM