用C#做了一个文本编辑器,
现在在菜单栏里加了一个“查找替换”的选项,现在想要实现的代码
谢谢
现在在菜单栏里加了一个“查找替换”的选项,现在想要实现的代码
谢谢
解决方案 »
- [提问]关于DataGridView中添加ComboBox实现下拉框的问题
- c# listView 如何设置整格背景色。(winfrom)
- 已经有C#基础的人,学习C#该怎么深入?
- C#中怎么判断在规定的时间内,用户无鼠标键盘等动作,然后提示他?
- 郁闷的SQL 2000 问题(C#),
- 怎样把unicode转换成字符,反之亦然
- div隐藏问题
- 质疑C#在Microsoft Visual Studio .NET开发工具中的地位!同时请教高手.
- 小问题
- 最近一直研究ado.net,眼直头大,希望斑竹总结一下!
- WEB打印?
- 在catch块中throw new exception(string,exception)有什么意义?
button1的click事件
{string str1; //存放要查找的文本
str1=textBox2.Text; //获取要查找的文本
start=richTextBox1.Find(str1,start,RichTextBoxFinds.MatchCase);
if(start==-1)
{
MessageBox.Show("已经查找到文件末尾","");
start=0;
}
else
{
start=start+str1.Length;
richTextBox1.Focus(); //设置焦点
}
}
textBox2的TextChanged事件
{start=0;//只要查找的文本改变,则把start位置为0}
button2的click事件
{
string str1,str2;
string str1=textBox2.Text;
string str2=textBox3.Text;
start=richTextBox1.Find(str1,start,RichTextBoxFinds.MatchCase); //查找下一个
while (start!=1)
{
richTextBox1.SelcetedText=str2; //查找下一个
start+=str2.Length; //下一次查找的其实位置
start=richTextBox1.Find(str1,start,RichTextBoxFinds.MatchCase);
}
MessageBox.Show("已经查找到文件末尾","");
start=0;
richTextBox1.Focus(); //设置焦点
}//以上是手写代码,如有错,自己更改
但这个东西不复杂,自己写一个吧.
要不你试一下string的replace方法?
{
string s = richTextBox1.Text;
string sFind = textBox1.Text;
string sReplace = textBox2.Text;
s = s.Replace(sFind, sReplace);
richTextBox1.Text = s;
}