C# 记事本小程序 实验报告(7)

2018-11-17 19:25

{ //向下查找时 if (IsDown) { postion = text.IndexOf(keyword,postion); if (postion!=-1) { pos = postion; //区分大小写时,向下查找时记录最后一个查找的位置 } } else if(IsUp) { upostion = text.LastIndexOf(keyword,upostion); if (upostion!=-1) { pos = upostion; //区分大小写时,记录向上查找的最后一个位置 } } } //不区分大小写时 else { keyword = keyword.ToLower(); //将大写转换为小写 text = text.ToLower(); //将大写转换为小写 //向下查找时 if (IsDown) { postion = text.IndexOf(keyword,postion); if (postion!=-1) { pos = postion; //不区分大小写时记录向下查找的最后一个位置 } } //向上查找时 else if(IsUp) { upostion = text.LastIndexOf(keyword,upostion); if (upostion!=-1) { 31 / 39

pos = upostion; //不区分大小写时记录向上查找的最后一个位置 } } } //向下查找时 if (IsDown) { if (postion==-1) { MessageBox.Show(\已经查找完毕!\ postion =text.Length; } else { ((MainForm)this.Owner).richTextBox1.Select(postion,keyword.Length); if (postion!=text.Length) { postion++; } pos = postion; this.Owner.Activate(); //激活窗体并给与他焦点 } } //向上查找时 else if(IsUp) { if (upostion==-1) { MessageBox.Show(\已经到文本顶端,请选择向下查找\ upostion =0; } else { ((MainForm)this.Owner).richTextBox1.Select(upostion,keyword.Length); if (upostion!=0) { upostion--; } this.Owner.Activate(); //激活窗体并给与他焦点 } 32 / 39

} } } #endregion #region 其他各个按钮功能 //取消按钮事件 private void Cancel_Click(object sender, EventArgs e) { this.Close(); } //选择向上查找事件 private void 向上_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked) { IsUp = true; IsDown = false; upostion = postion; } } //选择向下查找事件 private void 向下_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked) { IsDown = true; IsUp = true; postion = upostion; } } //选择区分大小写时 private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked) { IsCase = true; postion =pos; upostion =pos; } else 33 / 39

{ IsCase = false; postion =pos; upostion =pos; } } #endregion #region 窗体加载时 //设置窗体加载事件 private void Search_Load(object sender, EventArgs e) { text = ((MainForm)this.Owner).richTextBox1.Text; upostion = text.Length; } #endregion } } 3、替换代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 记事本 { public partial class Replacefrm : Form { public Replacefrm() 34 / 39

{ InitializeComponent(); } #region 变量初始化 int postion = 0;//初始化向下查找的关键字位置 bool Iscase = false;//是否区分大小写 string newword =\替换的内容 private string keyword =\初始化要查找的关键字 public RichTextBox rtb; int start = 0;//替换时查找的起始位置 int i = 0; #endregion #region 查找下一处处理 private void SearchNext_btn_Click(object sender, EventArgs e) { //如果查找框为空,则直接返回 if (ReplaceObj_txt.Text == \ { return; } else { keyword = ReplaceObj_txt.Text; //要查找的内容 //区分大小写时 if (Iscase) { postion = rtb.Find(keyword,postion,RichTextBoxFinds.MatchCase); if (postion==-1) { MessageBox.Show(\对不起!找不到与“\”内容相匹配的信息,或者已经查找完毕!\ postion = 0; } else { postion = postion + keyword.Length; //从找到的位置开始继续查找 rtb.Focus(); //获取焦点 } } 35 / 39


C# 记事本小程序 实验报告(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:小学语文教师学科专业知识考试试题及答案1

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: