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