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

2018-11-17 19:25

{ this.状态栏ToolStripMenuItem.Checked = true; this.toolStripStatusLabel1.Text = \正在执行:文本读写操作 \ this.toolStripStatusLabel2.Text = \当前文档计数:\ this.toolStripStatusLabel3.Text = \ this.toolStripStatusLabel4.Text =\光标所在:\+\第\+ row + \行 第\+ col + \列 |\ timer1.Start(); } #endregion #region 菜单栏-文件-新建 ///

摘要 /// 设置新建选项,如果已有文本在文本框中,则需要先提示用户进行保存 /// ///

{ DialogResult dialg = MessageBox.Show(\文件已被修改是否要保存?\保存文件\ MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question); switch (dialg) { case DialogResult.Yes: { 另存为_Click(sender, e); richTextBox1.Clear(); IsSaved = false; Isnewnote = true; //表示此时文本为新建文本 this.Text = \新建-记事本\ break; } case DialogResult.No: { richTextBox1.Clear(); IsSaved = false; Isnewnote = true; //表示此时文本为新建文本 this.Text = \新建-记事本\ break; } 7 / 39

case DialogResult.Cancel: { break; } } } else if (richTextBox1.Modified==false) { richTextBox1.Clear(); this.Text = \新建-记事本\ Isnewnote = true; richTextBox1.Modified = true;//重置文本框标识符 } else if (IsSaved) { richTextBox1.Clear(); IsSaved = false; Isnewnote = true; //表示此时文本为新建文本 this.Text = \新建-记事本\ richTextBox1.Modified=false; } } 8 / 39

} catch (System.Exception ex) { MessageBox.Show(ex.Message); } } #endregion #region 菜单栏-文件-打开 ///

摘要 /// 想要实现打开文件功能,要注意的一点就是,在打开文件的时候一定要指定解码方式 /// 不然会出现中文乱码现象 /// C#默认解码方式为unicode方式,而中文为gb2312,因此必须指定其中文的解码方式 ///

(*.cs)|*.cs|Word文档(*.doc)|*.doc|所有文件(*.*)|*.*\指定所能打开的文件格式 openFileDialog1.FileName = \无标题\ openFileDialog1.AddExtension = true; //如果用户省略扩展名,将自动添加扩展名 if (openFileDialog1.ShowDialog()==DialogResult.OK) { StreamReader sr StreamReader(openFileDialog1.FileName,System.Text.Encoding.Default); = new richTextBox1.Text = sr.ReadToEnd(); //从流的当前位置到流的结束位置 this.Text = openFileDialog1.SafeFileName + \记事本\ sr.Close(); Filename = openFileDialog1.FileName; richTextBox1.Modified=false; //将文本框标示符重置 openfile = true; //重置标识符 IsSaved = true; } } else if (richTextBox1.Modified) { DialogResult r = MessageBox.Show(\是否将更改保存到 无标题?\\无标题\ MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); int g = (int)r; //当g为6时表示选择的是“是”,为7是选择的是“否” 10 / 39


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

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

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

马上注册会员

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