




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、武夷学院实验报告课程名称:_.NET程序设计_ 项目名称:_ C#控件应用 姓名:_陈东煌_专业:_计算机科学与技术_ 班级:_1_学号:_35_同组成员_一、 实验预习部分 注:1、实验预习部分包括实验环境准备和实验所需知识点准备。2、若是单人单组实验,同组成员填无。:1. 软硬件环境:PC一台、Windows系统、Visual Studiao 20102. 实验准备内容:(1) Windows窗体应用程序 Windows窗体应用程序是运行在用户计算机本地的基于Windows的应用程序,提供丰富的用户界面以实现用户交互,并可以访问操作系统服务和用户计算环境提供的资源,从而实现各种复杂功能的应
2、用程序。由于Windows窗体应用程序涉及复杂的用户界面和事件处理过程,故一般通过集成开发环境Visual Studio开发和调试Windows窗体应用程序。(2) 创建Windows窗体应用程序一般步骤1、创建Windows窗体项目2、创建用户界面3、添加程序代码4、运行和测试程序5、保存项目(3) 常用Windows窗体控件 Label控件、LinkLabel控件、TextBox控件、RichTextBox控件、MaskedTextBox控件、Button控件;RadioButton控件、CheckBox控件、GroupBox控件;ComboBox控件、ListBox控件、CheckedL
3、istBox控件;PictureBox控件、ImageList控件;Timer控件(4) 通用对话框OpenFileDialogSaveFileDialogColorDialogFontDialogPageSetupDialogPrintDialogPrintPreviewDialogFolderBrowserDialog(5) 菜单和工具栏(1) 主菜单:提供窗体的菜单系统。MenuStrip控件用于实现主菜单(2) 上下文菜单:通过鼠标右击某对象而弹出的菜单。ContextMenuStrip控件用于实现上下文菜单。(3)工具栏:通过单击工具栏上的图标,可以执行相关的操作。ToolStrip
4、控件用于实现工具栏。(6) 多重窗体1、添加新窗体2、调用其他窗体:要调用其他窗体,可以再相应的按钮/菜单命令的事件处理程序中,通过下列类似代码,创建(实例化)并显示一个窗体。例如,要显示Form2,可以使用下列代码: Form2f2 =new Form2();/创建Form2的实例 f2.ShowDialog();/显示Form2的实例。也可以使用f2.Show()调用 3、多重窗体应用(7) 多文档界面(1)创建MDI父窗体(2)创建MDI子窗体在MDI父窗体的主菜单或工具栏命令事件处理程序中,可以使用代码创建并显示MDI子窗体的实例:Form2 FormChild=new Form2()
5、;FormChild.MdiParent=this;FormChild.show(); (3)处理MDI子窗体二、 实验过程记录 注:实验过程记录要包含实验目的、实验原理、实验步骤,页码不够可自行添加。:实验指导书:实验15-1实验15615-1:(1) 创建Windows窗体应用程序(2)窗体设计,如下:(3)生成并处理CtoF_Click事件和FtoC_Click事件的代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Dr
6、awing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace sy15_1 public partial class Form1 : Form public Form1() InitializeComponent(); private void CtoF_Click(object sender, EventArgs e) double c = 9 * double.Parse(textBoxC.Text) / 5 + 32; textBoxF
7、.Text = c.ToString(); private void FtoC_Click(object sender, EventArgs e) double f = 5 * (double.Parse(textBoxF.Text) - 32) / 9; textBoxC.Text = f.ToString(); (4)运行并测试应用程序 15-2:(1) 创建Windows应用程序(2) 窗体设计,如下:(3) 创建处理控件事件代码如下:using System;using System.Collections.Generic;using System.ComponentModel;usi
8、ng System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace sy12_2 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) Message.Text = stuName.Text
9、+ ,您好,欢迎进入C#世界!n; Message.Text += 您的密码是: + Password.Text; if(radioButton1.Checked) Message .Text+=n您的性别是:+radioButton1.Text ; else if (radioButton2.Checked) Message.Text +=n您的性别是:+radioButton2.Text ; if (School.SelectedIndex -1) Message.Text += n您的学校是: + School.SelectedItem.ToString(); else Message.
10、Text += n您没有选择学校; if (Major.SelectedIndex -1) Message.Text += n您的专业是: + Major.SelectedItem.ToString(); else Message.Text += n您没有选择专业; Message.Text += n您的爱好是; if (checkBox1.Checked) Message.Text += checkBox1.Text + ; if (checkBox2.Checked) Message.Text += checkBox2.Text + ; if (checkBox3.Checked) Mes
11、sage.Text += checkBox3.Text + ; if (checkBox4.Checked) Message.Text += checkBox4.Text + ; if (!checkBox1.Checked) & (!checkBox2.Checked) & (!checkBox3.Checked) & (!checkBox4.Checked) Message.Text += 您居然没有兴趣爱好!; (4) 运行并测试应用程序15-3:(1) 创建Windows应用程序(2) 窗体设计,如下:(3) 创建处理控件事件 生成并处理,代码如下:using System;using
12、 System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace sy15_3 public partial class Form1 : Form public Form1() InitializeComponent(); private void openFileDia
13、log1_FileOk(object sender, CancelEventArgs e) private void Open_Click(object sender, EventArgs e) OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = C:C#LABimages; openFileDialog1.Filter = Image Files(*.BMP;*.JPG;*.GIF|*.BMP;*.JPG;*.GIF; openFileDialog1.Restore
14、Directory = true; if (openFileDialog1 .ShowDialog()=DialogResult .OK) pictureBox1.Load(openFileDialog1.FileName); private void Stretch_Click(object sender, EventArgs e) pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; private void Center_Click(object sender, EventArgs e) pictureBox1.SizeMode
15、= PictureBoxSizeMode.CenterImage; private void Zoom_Click(object sender, EventArgs e) pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; private void AutoSize_Click(object sender, EventArgs e) pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; (4) 运行并测试应用程序拉伸后:居中后:缩放后:自动大小: 15-4: (1)创建Windows应用程序 (2)窗
16、体设计,如下: (3)创建处理控件事件的方法 代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace sy15_4public partial class Form1:Form private long ticks;
17、 public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if(button1 .Text =开始) button1.Text = 暂停; timer1.Start(); else button1.Text = 开始; timer1.Stop(); private void button2_Click(object sender, EventArgs e) button1.Text = 开始; timer1.Stop(); label1.Text = 00:00:0
18、0:00; private void Form1_Load(object sender, EventArgs e) ticks =0; private void timer1_Tick(object sender, EventArgs e) ticks+; long hours = ticks / 360000; long minutes = (ticks - hours * 360000) / 6000; long seconds = (ticks - hours * 360000 - minutes * 6000) / 100; long ms = ticks - hours * 3600
19、00 - minutes * 6000 - seconds * 100; label1.Text = string.Format(0:00:1:00:2:00:3:00, hours, minutes, seconds, ms); (4)运行并测试应用程序 点击开始按钮,然后点击暂停按钮: 点击停止按钮,计时器清零: 15-5: (1)创建Windows应用程序 (2)窗体设计,如下: (3)程序代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using
20、 System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace sy15_5 public partial class Form1 : Form public Form1() InitializeComponent(); private void buttonOpen_Click(object sender, EventArgs e) OpenFileDialog openFileDialog1 = new OpenFile
21、Dialog(); openFileDialog1.InitialDirectory = c; openFileDialog1.Filter = rft files(*.rtf)|*.rtf; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if(openFileDialog1 .ShowDialog()=DialogResult.OK) richTextBox1.LoadFile(openFileDialog1.FileName); private void buttonSave_Click(
22、object sender, EventArgs e) SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = c; saveFileDialog1.Filter = rft files(*.rtf)|*.rtf; saveFileDialog1.FilterIndex = 1; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog()=DialogResult .OK) richT
23、extBox1.SaveFile(saveFileDialog1.FileName); private void buttonFont_Click(object sender, EventArgs e) FontDialog fontDialog1 = new FontDialog(); fontDialog1.ShowColor = true; fontDialog1.Font = richTextBox1.SelectionFont; fontDialog1.Color = richTextBox1.SelectionColor; if(fontDialog1.ShowDialog()!=
24、DialogResult.Cancel) richTextBox1.SelectionFont = fontDialog1.Font; richTextBox1.SelectionColor = fontDialog1.Color; private void buttonExit_Click(object sender, EventArgs e) this.Close(); (4)运行并测试应用程序 打开电脑文件夹中的*.rtf文件, 点击“字体”按钮,经修改字体后如下: 再点击保存文件到指定文件夹中。 15-6: (1)创建Windows应用程序 (2)窗体设计,如下: (3)创建处理控件事
25、件的方法 代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace sy15_6 public partial class Form1 : Form public Form1() InitializeComponent()
26、; private void richTextBox1_TextChanged(object sender, EventArgs e) private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e) private void 新建NToolStripMenuItem_Click(object sender, EventArgs e) richTextBox1.Clear(); this.Text = 新建文档; private void 打开OToolStripMenuItem_Click(object sender, Ev
27、entArgs e) OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = c; openFileDialog1.Filter = rft files(*.rtf)|*.rtf; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() = DialogResult.OK) richTextBox1.LoadFile
28、(openFileDialog1.FileName); private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = c; saveFileDialog1.Filter = rft files(*.rtf)|*.rtf; saveFileDialog1.FilterIndex = 1; saveFileDialog1.RestoreDirect
29、ory = true; if (saveFileDialog1.ShowDialog()=DialogResult .OK) richTextBox1.SaveFile(saveFileDialog1.FileName); private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) this.Close(); private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e) richTextBox1.Cut(); private void 复制CToolStripMenuItem_Click(object sender, EventArgs e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2022年度护士工作总结范文(26篇)
- 海水(咸水)淡化工程可行性研究报告
- 研发安全运维
- 南通职业大学《单片机综合实训》2023-2024学年第二学期期末试卷
- 广东轻工职业技术学院《智能控制工程基础》2023-2024学年第二学期期末试卷
- 宁夏工商职业技术学院《大气辐射学Ⅱ》2023-2024学年第二学期期末试卷
- 重庆工商大学派斯学院《新媒体技术与创作》2023-2024学年第二学期期末试卷
- 南京师范大学泰州学院《工程图学C》2023-2024学年第二学期期末试卷
- 中山职业技术学院《汽车电气系统检修》2023-2024学年第二学期期末试卷
- 兰州交通大学《施工测量实训》2023-2024学年第二学期期末试卷
- 《企业的绩效管理问题与优化策略的分析案例-以舍得酒业公司为例9100字》
- 超星尔雅学习通《移动互联网时代的信息安全与防护(南京师范大学)》2025章节测试附答案
- (部编版)语文四年级上册课外阅读“天天练”100篇,附参考答案
- DB31∕701-2020 有色金属铸件单位产品能源消耗限额
- 统编版语文六年级下册古诗词诵读10《清平乐》
- 社群营销的年度工作策略计划
- 微弱的光亮(2024年山东烟台中考语文试卷记叙文阅读试题)
- 国际贸易居间协议样本
- 2024爱德华EDWARDS消防报警系统产品技术手册
- 康复医疗评定课件
- 预制板粘贴碳纤维加固计算表格
评论
0/150
提交评论