richtextbox 里面有内容 在里面查询某个字符串,查询到就选定该字符串 如何实现?
解决方案 »
- 向数据库插入数据
- C#中如何根据传入的对象自动创建一个xml文件?
- (求贴)关于冒泡排序的改进 如何键盘输入进行排序 大家帮忙看看啊
- 為什麼我的程式占用CPU這麼高啊?
- 同样是session语句:session["name"]=textbox1.text;和label2.text=session["name"].tostring(); 不同
- 请教哪位高手有Anakrino9所配合的IIL中间语言参考手册?给100分!!
- 请问,如何将二进制图片插入到Sybase数据库?
- 哪位朋友有最新版本的Developer Express Editors和Developer Express Grids控件?
- 简单问题,取整用什么函数?
- 简单问题~~怎么判断输入字符串为空?
- 【高分】使用钩子无法彻底屏蔽按键的问题
- c# 如何获取dvd章节及字幕信息?
richTextBox1.Select(i,3);
public void SelectMyString()
{
// Create a string to search for the word "fox".
String searchString = "fox";
// Determine the starting location of the word "fox".
int index = textBox1.Text.IndexOf(searchString, 16, 3);
// Determine if the word has been found and select it if it was.
if (index != -1)
{
// Select the string using the index and the length of the string.
textBox1.Select(index, searchString.Length);
}
}这是MSDN上提供的方法。
richTextBox1.Select(i,3);
查找到的是第一个,如果我想让他继续找第二个,怎么办
我要放个按钮上去,点下一个就去找下一个了。
怎么我的找不到?
private void button2_Click(object sender, EventArgs e)
{
int i = richTextBox1.Text.IndexOf("123");
richTextBox1.Select(i, 3);
}
加了个
richTextBox1.Focus();
就解决了
int index = this.richTextBox1.Find(s);
if (index < 0)
{
MessageBox.Show("查找不到");
return;
}
this.richTextBox1.SelectionStart = index;
this.richTextBox1.SelectionLength = s.Length;
this.richTextBox1.Focus();
int j = m.IndexOf("123");
if (j >= iii)
{
iii += j; MessageBox.Show(iii.ToString());
richTextBox1.Select(iii, 3);
richTextBox1.Focus(); }
else(Messagebox.show("查找不到"+"123"));
iii++;
这个我写的 刚才试了下 可以查找下一个,最好在光标改变的时候把iii清0;
int j = m.IndexOf("123");
if (j >=0)
{
iii += j; MessageBox.Show(iii.ToString());
richTextBox1.Select(iii, 3);
richTextBox1.Focus();
iii += 3; }
else
MessageBox.Show("不能找到");
这个好了
刚才那个有问题