求C#记事本程序替换功能的程序代码
2013-11-09
展开全部
变量名你注意一下:
private void button2_Click(object sender, EventArgs e)
{
try
{
mainform.ffind = true;
mainform.tBox2 = textBox1.Text;
if (mainform.mtBox1.SelectedText == mainform.mtBox1.Text)
mainform.mtBox1.Select(0, 0);
fl = textBox1.Text;
fr = textBox2.Text;
if (checkBox1.Checked)
{
mr = mainform.mtBox1.Text;
tt = textBox1.Text;
mainform.f2checkbox = true;
}
else
{
mr = mainform.mtBox1.Text.ToLower();
tt = textBox1.Text.ToLower();
mainform.f2checkbox = false;
}
if (mainform.mtBox1.SelectedText == tt)
mainform.mtBox1.SelectedText = textBox2.Text;
mainform.ffl = 1;
if (mr.IndexOf(tt, mainform.mtBox1.SelectionStart + mainform.mtBox1.SelectedText.Length) >= 0)
{
mainform.mtBox1.Select(mr.IndexOf(tt, mainform.mtBox1.SelectionStart + mainform.mtBox1.SelectedText.Length), textBox1.Text.Length);
mainform.mtBox1.ScrollToCaret();//当屏幕显示不了时,实现滚动
}
else MessageBox.Show(("找不到\"" + textBox1.Text + "\""), "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch { }
}
private void button2_Click(object sender, EventArgs e)
{
try
{
mainform.ffind = true;
mainform.tBox2 = textBox1.Text;
if (mainform.mtBox1.SelectedText == mainform.mtBox1.Text)
mainform.mtBox1.Select(0, 0);
fl = textBox1.Text;
fr = textBox2.Text;
if (checkBox1.Checked)
{
mr = mainform.mtBox1.Text;
tt = textBox1.Text;
mainform.f2checkbox = true;
}
else
{
mr = mainform.mtBox1.Text.ToLower();
tt = textBox1.Text.ToLower();
mainform.f2checkbox = false;
}
if (mainform.mtBox1.SelectedText == tt)
mainform.mtBox1.SelectedText = textBox2.Text;
mainform.ffl = 1;
if (mr.IndexOf(tt, mainform.mtBox1.SelectionStart + mainform.mtBox1.SelectedText.Length) >= 0)
{
mainform.mtBox1.Select(mr.IndexOf(tt, mainform.mtBox1.SelectionStart + mainform.mtBox1.SelectedText.Length), textBox1.Text.Length);
mainform.mtBox1.ScrollToCaret();//当屏幕显示不了时,实现滚动
}
else MessageBox.Show(("找不到\"" + textBox1.Text + "\""), "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch { }
}
2013-11-09
展开全部
mainform.ffind=true;应该是他在记事本的主界面中定义的一个bool型变量 具体用来做什么我就不知道了 因为不是我做的
mtBox1应该记事本的文本框的名字
mainform.mtBox1.SelectedText 这句的意思是主界面里面的mtBox1的选定的文本方法 用来获得文本框中选定的文本
mtBox1应该记事本的文本框的名字
mainform.mtBox1.SelectedText 这句的意思是主界面里面的mtBox1的选定的文本方法 用来获得文本框中选定的文本
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-09
展开全部
以下是个参考,实现了大体的查找替换功能,你可能要改写成你需要的代码,具体的细节处理由你自己来写:)
int startIndex = 0;
private void buttonFind_Click(object sender, System.EventArgs e)
{
string words = this.textBox1.Text;
string tobefound = this.textBox2.Text;//textBox2中放要查找的字符
if(startIndex == -1)//not found
return;
startIndex = words.IndexOf(tobefound,startIndex);
if(startIndex >= 0 && startIndex < words.Length)
{
this.textBox1.Select(startIndex,tobefound.Length);
this.textBox1.Focus();
startIndex += tobefound.Length;
}
}
private void buttonReplace_Click(object sender, System.EventArgs e)
{
if(this.textBox1.SelectedText.Length > 0)
this.textBox1.SelectedText = this.textBox3.Text;//textBox3中放要替换的字符
}
int startIndex = 0;
private void buttonFind_Click(object sender, System.EventArgs e)
{
string words = this.textBox1.Text;
string tobefound = this.textBox2.Text;//textBox2中放要查找的字符
if(startIndex == -1)//not found
return;
startIndex = words.IndexOf(tobefound,startIndex);
if(startIndex >= 0 && startIndex < words.Length)
{
this.textBox1.Select(startIndex,tobefound.Length);
this.textBox1.Focus();
startIndex += tobefound.Length;
}
}
private void buttonReplace_Click(object sender, System.EventArgs e)
{
if(this.textBox1.SelectedText.Length > 0)
this.textBox1.SelectedText = this.textBox3.Text;//textBox3中放要替换的字符
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询