C课程设计说明书_第1页
C课程设计说明书_第2页
C课程设计说明书_第3页
C课程设计说明书_第4页
C课程设计说明书_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、课 程 设 计 说 明 书设计题目:记事本仿真程序设计指导教师:魏明军学 院:信息工程学院学生姓名:赵芮学 号:2专业班级:12计算机三班2013年06月16日成绩评定姓名:学号:班级:评分项目分数程序功能完善(30分)回答问题正确(20分)设计报告规范(30分)(结构完整,图表正确,文字通顺,版面工整)代码质量(10分)(类、方法及变量等的命名符合规范,主要方法及字段有注释,程序有适当缩进)平时表现(10分)(独立完成,态度认真)评定成绩目 录一、系统概述及设计思想11 系统开发基本目标12 系统开发设计思想1二、关键技术1 1 C#基本技术12 Windows窗体设计1三、系统功能设计21

2、 主程序界面22 查找界面33 替换界面44 其它界面4四、各功能代码设计61 主窗体代码实现62 查找窗体代码实现113 替换窗体代码实现13五、使用说明151 “文件”菜单的使用152 “编辑”菜单的使用163 “格式”菜单的使用16六、设计体会16七、参考文献17一、系统开发目标及设计思想1系统开发基本目标该系统包括以下功能:(1)文本文件的新建、打开、保存、另存、关闭、退出。(2)编辑操作:复制、剪切、粘贴、撤销。(3)环境的设置:改变字体、改变前景及背景颜色。(4)软件的开发信息。如学生基本情况的输入。2系统开发设计思想(1)采用学校现有的软件和硬件环境以及设计要求开发系统。(2)系

3、统采用模块化程序设计方法,既便于系统功能的各种组合和修改,又便于未参与开发的技术维护人员补充,维护。(3)程序设计符合面向对象的思想和原则。(4)要有良好的程序风格(类、方法及变量等的命名要符合规范;类、方法及字段要有注释;程序有适当缩进)(5)采用文件对数据进行存储。(6)人机界面美观,操作方便、实用。二、关键技术1 C#基本技术 (1) )if.else.语句等的使用。(2)try、catch异常处理,如:在打开窗体代码用的异常处理。try fileName = openFileDilog.FileName; this.Text = fileName + -记事本; myStream =

4、new StreamReader(fileName,Encoding.GetEncoding (gb2312); RichTextBox.Text = myStream.ReadToEnd(); myStream.Close(); catch (Exception ex) MessageBox.Show(不能打开文件!错误: + ex.Message); (3)各种运算的使用,如赋值运算和逻辑运算的使用。if (flag = -1 | flag f1.RichTextBox.Text.Length)radioButton1.Checked = true(4)类的继承的使用,如Form1、For

5、m2、Form3均继承于Form。(5)方法和变量的定义和使用以及访问修饰符的使用,如要将RichTextBox窗体的访问修饰符由private改为public,以便于在在Form2中的使用。2 Windows窗体设计菜单是软件界面设计的一个重要组成方面。它描述着一个软件的大致功能和风格。所以在程序设计中处理好、设计好菜单,对于一个软件开发是否成功有着比较重要的意义。 Visual C#是.Net框架中的一个重要组成部分,也是微软公司推出的下一代主流程序开发语言。它在设计、开发程序界面的时候和以前的某些程序开发语言有所不同。这一点也表现在其的菜单编程方面。面向菜单编程中遇到的主要的问题大致可以

6、分为二种:添加菜单项、删除菜单项。当然在处理以上二类问题时候,还会遇到诸如:如何添加菜单项所对应的事件,如何为菜单项添加快捷键等一些小的问题。此次开发过程中由于之使用了很简单的菜单,所以直接运用了C#工具箱中的MenuStrip进行设计。要正确处理窗体、控件、事件,并要注意窗体和控件的Name和Text属性。 三、系统功能设计1 主程序界面主窗体完成大部分的系统功能,包括文件的新建、打开、保存等功能。设计如下:向主窗体中添加一个MenuStrip控件、一个RichTextBox控件、一个StatusStrip控件,添加MainMenu的子菜单(“文件”菜单包括“新建”、“打开”、“保存”、“另

7、存为”、“关闭”、“退出”子菜单,“编辑”菜单包括“复制”、“粘贴”、“剪切”、“查找”、“替换”、“全选”、“时间/日期”、“撤销”,“格式”包括“设置字体”、“设置颜色”、“自动换行”子菜单,其中“设置颜色“包括“前景颜色”和“背景颜色”,“查看”包括“状态栏”,“帮助”包括“关于记事本”),并为各个子菜单添加相应代码。设置各个控件的属性如表1所示,设置完毕后的主程序界面如图1所示,记事本整体构架如图2所示。对象属性设置值控件功能Form1Text无标题-记事本窗口标题栏的显式内容menuStrip1(Name)MainMenu添加菜单richTextBox1(Name)RichTextB

8、ox用于写入文本statusStrip1(Name)StripStatusLabel用于统计当前文本字数表1 控件对象属性列表 图1 主界面显示记事本文件编辑查看新建打开保存另存为 关闭退出撤消剪切复制粘帖查找替换全选格式帮助状态栏设置字体设置颜色自动换行关于记事本 图2 记事本整体构架2查找界面查找窗体完成查找文本的功能。设计如下:向窗体中添加botton1、botton2两个Botton按钮,一个CheckBox控件,radioBotton1、radioBotton2两个RadioBotton控件,一个Label控件,一个TextBox控件,一个GroupBox控件。设置各个控件的属性如表

9、2所示,设置完毕后的主程序界面如图3所示。表2 控件对象属性列表对象属性设置值控件功能Form2Text查找窗口标题栏的显式内容botton1Text查找下一处按钮的显示内容botton2Text取消按钮的显示内容radioBotton1Text向下控件的显示内容radioBotton2Text向上控件的显示内容checkBox1Text区分大小写控件的显示内容label1Text查找内容:标签的显示内容groupBox1Text方向控件的显示内容图3 查找界面3替换界面替换窗体完成查找并替换文本的功能。设计如下:向窗体中添加botton1、botton2、botton3、botton4四个B

10、otton按钮,一个CheckBox控件,label1、label2两个Label控件,textBox1、textBox2两个TextBox控件。设置各个控件的属性如表3所示,设置完毕后的主程序界面如图4所示。表2 控件对象属性列表对象属性设置值控件功能Form3Text替换窗口标题栏的显式内容botton1Text查找下一处按钮的显示内容botton2Text替换按钮的显示内容Botton3Text全部替换按钮的显示内容Botton4Text取消按钮的显示内容checkBox1Text区分大小写控件的显示内容label1Text查找内容:标签的显示内容label2Text替换为:标签的显示内

11、容 图4 替换界面4其他界面关于记事本界面和退出时提示是否保存界面分别如图5和图6所示。 图5 记事本开发信息 图6 提示 四、各功能代码设计1 主窗体代码实现using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;namespace NotePad public partial class Form1 :

12、 Form string fileName;/文件名 public Form1() InitializeComponent(); private void Form1_SizeChanged(object sender, EventArgs e) RichTextBox.SetBounds(this.ClientRectangle.Left, this.ClientRectangle.Top + MainMenu.Height, this.ClientRectangle.Right, this.ClientRectangle.Bottom); private void FileNew_Clic

13、k(object sender, EventArgs e)/新建窗体代码 this.Text = 无标题-记事本; RichTextBox.Text = ; fileName = ; private void FileOpen_Click(object sender, EventArgs e)/打开窗体代码 StreamReader myStream = null; OpenFileDialog openFileDilog = new OpenFileDialog(); openFileDilog.Filter = text files(*.txt)|*.txt; if (openFileDi

14、log.ShowDialog() = DialogResult.OK) try fileName = openFileDilog.FileName; this.Text = fileName + -记事本; myStream = new StreamReader(fileName,Encoding.GetEncoding (gb2312); RichTextBox.Text = myStream.ReadToEnd(); myStream.Close(); catch (Exception ex) MessageBox.Show(不能打开文件!错误: + ex.Message); privat

15、e void FileSave_Click(object sender, EventArgs e)/保存窗体代码 SaveFileDialog saveDig = new SaveFileDialog(); saveDig.Filter = 文本文档(*.txt)|*.txt; saveDig.FileName = *.txt; if (saveDig.ShowDialog() = DialogResult.OK) StreamWriter sw = new StreamWriter(saveDig.FileName, false, System.Text.Encoding.Default);

16、 sw.Write(this.RichTextBox.Text); sw.Close(); this.Text = saveDig.FileName; private void FileSaveAs_Click(object sender, EventArgs e)/另存为代码 StreamWriter myStream; SaveFileDialog saveFileDilog = new SaveFileDialog(); saveFileDilog.Filter = text files(*.txt)|*.txt; if (saveFileDilog.ShowDialog() = Dia

17、logResult.OK) fileName = saveFileDilog.FileName; myStream = new StreamWriter(fileName); this.Text = fileName + -记事本; myStream.Write(RichTextBox.Text); myStream.Close(); private void FileClose_Click(object sender, EventArgs e)/关闭窗体代码 if (RichTextBox.Text = ) this.Close(); else DialogResult result; re

18、sult = MessageBox.Show(是否将更改保存到“无标题”?, 提示, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result = DialogResult.Yes) FileSaveAs_Click(sender, e); /保存现有信息。 else if (result = DialogResult.No) this.Close(); else private void FileExit_Click(object sender, EventArgs e)/退出窗体代码 if (RichTextBo

19、x.Text = ) this.Close(); else DialogResult result; result = MessageBox.Show(是否将更改保存到“无标题”?, 提示, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result = DialogResult.Yes) FileSaveAs_Click(sender, e); /保存现有信息。 else if (result = DialogResult.No) this.Close(); private void EditCopy_Click(o

20、bject sender, EventArgs e)/复制窗体代码 RichTextBox.Copy(); private void FilePaste_Click(object sender, EventArgs e)/粘贴窗体代码 RichTextBox.Paste(); private void FileCut_Click(object sender, EventArgs e)/剪切窗体代码 RichTextBox.Cut(); private void SelectFont_Click(object sender, EventArgs e)/设置字体代码 FontDialog dlg

21、= new FontDialog(); if (dlg.ShowDialog() = DialogResult.OK) RichTextBox.Font = dlg.Font; private void SelectForeColor_Click(object sender, EventArgs e)/前景颜色窗体代码 ColorDialog dlg2 = new ColorDialog(); if (dlg2.ShowDialog() = DialogResult.OK) RichTextBox.ForeColor = dlg2.Color; private void SelectBackC

22、olor_Click(object sender, EventArgs e)/背景颜色窗体代码 ColorDialog dlg1 = new ColorDialog(); if (dlg1.ShowDialog() = DialogResult.OK) RichTextBox.BackColor = dlg1.Color; private void About_Click(object sender, EventArgs e)/关于记事本代码 MessageBox.Show(this, 文本编括辑器 + Environment.NewLine + 12计算机3班赵芮 + Environment

23、.NewLine + 版本1.0, 文本, MessageBoxButtons.OKCancel, MessageBoxIcon.Information); private void Form1_Load_1(object sender, EventArgs e) this.Text = 无标题-记事本; fileName = ; RichTextBox.SetBounds(this.ClientRectangle.Left, this.ClientRectangle.Top + MainMenu.Height, this.ClientRectangle.Right, this.ClientR

24、ectangle.Bottom); private void Form1_SizeChanged_1(object sender, EventArgs e) RichTextBox.SetBounds(this.ClientRectangle.Left, this.ClientRectangle.Top + MainMenu.Height, this.ClientRectangle.Right, this.ClientRectangle.Bottom); private void RichTextBox_TextChanged_1(object sender, EventArgs e) Ric

25、hTextBox.SetBounds(this.ClientRectangle.Left, this.ClientRectangle.Top + MainMenu.Height, this.ClientRectangle.Right, this.ClientRectangle.Bottom); this.StripStatusLabel.Text = 当前字数: + this.RichTextBox.Text.Length; private void EditSeek_Click_1(object sender, EventArgs e)/查找窗体代码 Form2 f = new Form2(

26、); f.Owner = this; f.Show(); private void EditReplace_Click_1(object sender, EventArgs e)/替换代码 Form3 fs = new Form3(); fs.Owner = this; fs.Show(); private void EditSelectAll_Click_1(object sender, EventArgs e)/全选代码 this.RichTextBox.SelectAll(); private void EditDateAndTime_Click_1(object sender, Eve

27、ntArgs e)/时间日期窗体代码 RichTextBox.Text += 现在时间是: + DateTime.Now.ToString(); private void EditBackOut_Click_1(object sender, EventArgs e)/撤销代码 RichTextBox.Undo(); private void WordWrap_Click_1(object sender, EventArgs e) if (WordWrap.Checked = false) WordWrap.Checked = true; RichTextBox.WordWrap = true;

28、 else WordWrap.Checked = false; RichTextBox.WordWrap = false; private void StatusBar_Click_1(object sender, EventArgs e)/状态栏代码 if (this.StatusBar.Checked = false) this.StatusBar.Checked = true; this.toolStripStatusLabel1.Visible = true; this.RichTextBox.Height -= 22; else this.StatusBar.Checked = fa

29、lse; this.toolStripStatusLabel1.Visible = false; this.RichTextBox.Height += 22; 2 “查找”窗体代码实现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 NotePad public partial

30、 class Form2 : Form int flag; public Form2() InitializeComponent(); private void Form2_Load(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)/查找下一处 Form1 f1 = (Form1)this.Owner; if (radioButton1.Checked = true) if (this.textBox1.Text.Length 0 & flag f1.RichTextBox.Te

31、xt.Length) MessageBox.Show(未查找到相关内容); flag = 0; else f1.RichTextBox.Select(flag, this.textBox1.Text.Length);/把查找到的内容选中,调用Select()方法 flag = flag + this.textBox1.Text.Length; f1.Activate(); if (radioButton2.Checked = true) if (this.textBox1.Text.Length 0 & flag f1.RichTextBox.Text.Length) MessageBox.S

32、how(未查找到相关内容); flag = 0; else f1.RichTextBox.Select(flag, this.textBox1.Text.Length);/把查找到的内容选中,调用Select()方法 flag = flag - this.textBox1.Text.Length; f1.Activate(); private void button2_Click(object sender, EventArgs e)/取消 this.Close(); private void Form2_Load_1(object sender, EventArgs e) private v

33、oid textBox1_TextChanged(object sender, EventArgs e) 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 NotePadpublic partial class Form3 : Form public Fo

34、rm3() InitializeComponent(); public int count = 0; public int a, b; private void button1_Click(object sender, EventArgs e)/查找下一处 Form1 f1 = (Form1)this.Owner; a = f1.RichTextBox.Text.IndexOf(textBox1.Text, count); if (a = 0) f1.RichTextBox.Select(a, textBox1.Text.Length); f1.RichTextBox.Focus(); cou

35、nt = a + 1; else MessageBox.Show(this.Owner, 找不到 + + textBox1.Text + , 记事本, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); private void button2_Click(object sender, EventArgs e)/替换 Form1 f1 = (Form1)this.Owner; a = f1.RichTextBox.Text.IndexOf(textBox1.Text, count);

36、if (a = 0) f1.RichTextBox.Text=f1.RichTextBox.Text.Remove(a, textBox1.Text.Length); f1.RichTextBox.Text=f1.RichTextBox.Text.Insert(a, textBox2.Text); else MessageBox.Show(this.Owner, 找不到 + + textBox1.Text + , 记事本, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); priva

37、te void button3_Click(object sender, EventArgs e)/全部替换 Form1 f1 = (Form1)this.Owner; f1.RichTextBox.Text = f1.RichTextBox.Text.Replace(textBox1.Text, textBox2.Text); private void button4_Click(object sender, EventArgs e)/取消 this.Close(); private void textBox1_TextChanged(object sender, EventArgs e)/查找文本框 if (textBox1.Text != null) button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; private void Form3_Load(obj

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论