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();这段代码