记事本 刚学C#。菜鸟中的菜鸟求查找功能和替换功能以及打印预览三项功能的代码。其他功能都实现了,是按照windows的那个记事本设计的。谢谢啦 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用对话框实现吧 参照windows 自带的试试 FindDiaog public int Find(char[ ] characterSet, int start, int end) System.Windows.Forms.RichTextBox 的成员 http://topic.csdn.net/u/20100618/21/380f6c0f-b2ca-47ec-b94e-de2e069b3123.html //查找文本 private void btnSearchNext_Click(object sender, System.EventArgs e) { //获得主窗体的引用 main ff = new main(); ff = (main)this.Owner; findText = 0; try { //向下查找 if(rbtnDown.Checked) { findText = ff.richTextBox1.SelectionStart + ff.richTextBox1.SelectionLength;//从光标处开始查找 if((findText = ff.richTextBox1.Text.IndexOf(textBox1.Text,findText)) == -1) { MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information); findText = ff.richTextBox1.Text.Length;//搜索到达终点 } else { //选中找到的文本,使其明显 ff.richTextBox1.Select(findText,textBox1.Text.Length); ff.richTextBox1.Focus(); findText += textBox1.Text.Length; } } //向上查找 else if(rbtnUp.Checked) { findText = ff.richTextBox1.SelectionStart - ff.richTextBox1.SelectionLength;//从光标处开始查找 if(findText >= 0 && findText <= ff.richTextBox1.Text.Length) { if((findText = ff.richTextBox1.Text.LastIndexOf(textBox1.Text,findText)) == -1) { MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information); } else { //选中找到的文本,使其明显 ff.richTextBox1.Select(findText,textBox1.Text.Length); ff.richTextBox1.Focus(); findText += textBox1.Text.Length; } } else { MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information); } } } catch(Exception ex) { MessageBox.Show(ex.Message); } } 替换 public int findPoint=0; private void btnReplace_Click(object sender, System.EventArgs e) { frmMain mainForm=(frmMain)this.Owner; if(txtContent.Text!=""&&txtReplace.Text!="") { if(mainForm.richTextBox.Text!="") { if((findPoint=mainForm.richTextBox.Text.IndexOf(txtContent.Text,findPoint))==-1) { MessageBox.Show("已到文本末尾,没有要查找和替换的内容","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); findPoint=0; } else { mainForm.richTextBox .Select(findPoint,txtContent.Text.Length); mainForm.richTextBox.SelectedText=txtReplace.Text; findPoint=findPoint+txtContent.Text.Length; mainForm.Activate(); } } else MessageBox.Show("无文本,无法查找和替换","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Error); } else MessageBox.Show("要查找和替换的内容不能为空,请输入要查找和替换的内容!","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Warning); }// 全部替换 private void btnAll_Click(object sender, System.EventArgs e) { frmMain mainForm=(frmMain)this.Owner; while((findPoint=mainForm.richTextBox.Text.IndexOf(txtContent.Text,findPoint))!=-1) { mainForm.richTextBox .Select(findPoint,txtContent.Text.Length); mainForm.richTextBox.SelectedText=txtReplace.Text; findPoint=findPoint+txtContent.Text.Length; } mainForm.Activate(); } //查找文本 private void btnSearchNext_Click(object sender, System.EventArgs e) { //获得主窗体的引用 main ff = new main(); ff = (main)this.Owner; findText = 0; try { //向下查找 if(rbtnDown.Checked) { findText = ff.richTextBox1.SelectionStart + ff.richTextBox1.SelectionLength;//从光标处开始查找 if((findText = ff.richTextBox1.Text.IndexOf(textBox1.Text,findText)) == -1) { MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information); findText = ff.richTextBox1.Text.Length;//搜索到达终点 } else { //选中找到的文本,使其明显 ff.richTextBox1.Select(findText,textBox1.Text.Length); ff.richTextBox1.Focus(); findText += textBox1.Text.Length; } } //向上查找 else if(rbtnUp.Checked) { findText = ff.richTextBox1.SelectionStart - ff.richTextBox1.SelectionLength;//从光标处开始查找 if(findText >= 0 && findText <= ff.richTextBox1.Text.Length) { if((findText = ff.richTextBox1.Text.LastIndexOf(textBox1.Text,findText)) == -1) { MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information); } else { //选中找到的文本,使其明显 ff.richTextBox1.Select(findText,textBox1.Text.Length); ff.richTextBox1.Focus(); findText += textBox1.Text.Length; } } else { MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information); } } } catch(Exception ex) { MessageBox.Show(ex.Message); } }出现了“未将对象引用设置到对象的实例”错误,该怎么办??? 在线等,传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。 vs2003 datagrid复杂报表,100分求教 关于正则表达式 如何取出能匹配的字符串 ? Jquery的问题 跪求小游戏代码(滑铁卢战役) 关于VS2005 DataGridView的一个问题 请大家帮忙关于:COM+ 已确定您的计算机运行的有效内存过少 高手指教小菜一下!!!crystalReportViewer 水晶报表怎么用? 如何让两个字段同时排序 请问如何使用C#调用远程COM? 求助已有打开的与此命令相关联的 DataReader,必须首先将它关闭。 VS2005保存文件后不自动编译
public int Find(char[ ] characterSet, int start, int end)
System.Windows.Forms.RichTextBox 的成员
http://topic.csdn.net/u/20100618/21/380f6c0f-b2ca-47ec-b94e-de2e069b3123.html
private void btnSearchNext_Click(object sender, System.EventArgs e)
{
//获得主窗体的引用
main ff = new main();
ff = (main)this.Owner;
findText = 0; try
{
//向下查找
if(rbtnDown.Checked)
{
findText = ff.richTextBox1.SelectionStart + ff.richTextBox1.SelectionLength;//从光标处开始查找
if((findText = ff.richTextBox1.Text.IndexOf(textBox1.Text,findText)) == -1)
{
MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information);
findText = ff.richTextBox1.Text.Length;//搜索到达终点
}
else
{
//选中找到的文本,使其明显
ff.richTextBox1.Select(findText,textBox1.Text.Length);
ff.richTextBox1.Focus();
findText += textBox1.Text.Length;
}
}
//向上查找
else if(rbtnUp.Checked)
{
findText = ff.richTextBox1.SelectionStart - ff.richTextBox1.SelectionLength;//从光标处开始查找
if(findText >= 0 && findText <= ff.richTextBox1.Text.Length)
{
if((findText = ff.richTextBox1.Text.LastIndexOf(textBox1.Text,findText)) == -1)
{
MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
//选中找到的文本,使其明显
ff.richTextBox1.Select(findText,textBox1.Text.Length);
ff.richTextBox1.Focus();
findText += textBox1.Text.Length;
}
}
else
{
MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public int findPoint=0;
private void btnReplace_Click(object sender, System.EventArgs e)
{
frmMain mainForm=(frmMain)this.Owner;
if(txtContent.Text!=""&&txtReplace.Text!="")
{
if(mainForm.richTextBox.Text!="")
{
if((findPoint=mainForm.richTextBox.Text.IndexOf(txtContent.Text,findPoint))==-1)
{
MessageBox.Show("已到文本末尾,没有要查找和替换的内容","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
findPoint=0;
}
else
{
mainForm.richTextBox .Select(findPoint,txtContent.Text.Length);
mainForm.richTextBox.SelectedText=txtReplace.Text;
findPoint=findPoint+txtContent.Text.Length;
mainForm.Activate();
}
}
else
MessageBox.Show("无文本,无法查找和替换","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
MessageBox.Show("要查找和替换的内容不能为空,请输入要查找和替换的内容!","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}// 全部替换
private void btnAll_Click(object sender, System.EventArgs e)
{
frmMain mainForm=(frmMain)this.Owner;
while((findPoint=mainForm.richTextBox.Text.IndexOf(txtContent.Text,findPoint))!=-1)
{
mainForm.richTextBox .Select(findPoint,txtContent.Text.Length);
mainForm.richTextBox.SelectedText=txtReplace.Text;
findPoint=findPoint+txtContent.Text.Length;
}
mainForm.Activate();
}
private void btnSearchNext_Click(object sender, System.EventArgs e)
{
//获得主窗体的引用
main ff = new main();
ff = (main)this.Owner;
findText = 0; try
{
//向下查找
if(rbtnDown.Checked)
{
findText = ff.richTextBox1.SelectionStart + ff.richTextBox1.SelectionLength;//从光标处开始查找
if((findText = ff.richTextBox1.Text.IndexOf(textBox1.Text,findText)) == -1)
{
MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information);
findText = ff.richTextBox1.Text.Length;//搜索到达终点
}
else
{
//选中找到的文本,使其明显
ff.richTextBox1.Select(findText,textBox1.Text.Length);
ff.richTextBox1.Focus();
findText += textBox1.Text.Length;
}
}
//向上查找
else if(rbtnUp.Checked)
{
findText = ff.richTextBox1.SelectionStart - ff.richTextBox1.SelectionLength;//从光标处开始查找
if(findText >= 0 && findText <= ff.richTextBox1.Text.Length)
{
if((findText = ff.richTextBox1.Text.LastIndexOf(textBox1.Text,findText)) == -1)
{
MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
//选中找到的文本,使其明显
ff.richTextBox1.Select(findText,textBox1.Text.Length);
ff.richTextBox1.Focus();
findText += textBox1.Text.Length;
}
}
else
{
MessageBox.Show("找不到\"" + this.textBox1.Text + "\"","myNotepad",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
出现了“未将对象引用设置到对象的实例”错误,该怎么办???