天津理工大学C#实验二(15页).docx





《天津理工大学C#实验二(15页).docx》由会员分享,可在线阅读,更多相关《天津理工大学C#实验二(15页).docx(15页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-天津理工大学C#实验二-第 15 页实验报告 学院(系)名称:计算机科学与工程学院姓名*学号*专业计算机科学与技术班级2015级 班实验项目实验二:Windows 窗体程序开发课程名称. NET程序设计课程代码0667066实验时间2017年4月25日实验地点7-215批改意见成绩教师签字: 一、 实验目的 (1) 掌握如何创建 Windows 窗体应用程序并熟悉程序的结构; (2) 掌握常用控件的使用;掌握控件的常用属性; (3) 理解事件的含义,并掌握控件的常用事件的含义及应用; (4) 掌握不同窗体之间传递数据的方式; (5) COM 组件的应用。 二、 实验环境 n 开发环境:PC机
2、,Windows 7操作系统;n 开发工具:Visual Studio 2010以上。三、 实验要求 (1) 认真完成实验内容,编写程序代码; (2) 输出实验的正确结果; (3) 书写并提交实验报告。 四、 实验内容1、 文本框控件使用利用文本框控件的属性及事件,按如下图窗体所示完成:当输入单价和数量时能够自动正确计算出商品价值。 代码实现:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.L
3、inq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication1 public partial class Form1 : Form double x = 0; int y = 0; public Form1() InitializeComponent(); private void label2_Click(object sender, EventArgs e) private void textBox1_TextChanged(object sender, EventArgs e) if
4、(textBox1.Text != ) try x = Convert.ToDouble(textBox1.Text); catch MessageBox.Show(请输入数字); if (textBox2.Text != ) textBox3.Text = (x * y).ToString(); private void textBox2_TextChanged(object sender, EventArgs e) if (textBox2.Text != ) try y = Convert.ToInt32(textBox2.Text); catch MessageBox.Show(请输入
5、数字); textBox3.Text = (x * y).ToString(); private void Form1_Load(object sender, EventArgs e) 运行结果:2、 Timer 组件的使用,要求利用 Timer 组件实现一时钟。代码实现:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.W
6、indows.Forms;namespace _2._2 public partial class Form1 : Form public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) timer1.Tick += new EventHandler(timer1_Tick); timer1.Interval = 1000; timer1.Start(); private void timer1_Tick(object sender, EventArgs e) textBox1
7、.Text = DateTime.Now.ToString(yyyy-MM-dd hh:mm:ss); 运行结果:3、 ComboBox 控件的使用已知数组 data 中存放政治面貌的值,试将 data 中的值初始化到 ComboBox控件中,并实现当选中某个值时将其显示在一个 TextBox 控件中。代码实现:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System
8、.Text;using System.Windows.Forms;namespace _2._3 public partial class Form1 : Form string data = 中共党员,共青团员,群众,民主党派,无党人士,其他; public Form1() InitializeComponent(); private void label2_Click(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e) for (int i = 0; i data.Length; i
9、+) comboBox1.Items.Add(datai); private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) textBox1.Text = comboBox1.Text; 运行结果:4、 ListView 控件的使用将二维数组中的信息在 ListView 控件中。二维数组用来模拟学生信息,具体信息: string, data = 20140001, 张三, 天津市西青区宾水西道391号 , 20140002, 李四, 天津市西青区宾水西道391号 ; 试完成如下功能: (1) 将 data 信息显
10、示在 ListView 控件中; (2) 当点击 ListView 控件中某个学生信息时,将相应的信息显示在对应的文本框控件中。 代码实现: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 _2._4 public partial class Form1 : Form stri
11、ng data1 = 1,20140001, 张三, 天津市西青区宾水西道391号 ; string data2 = 2, 20140002, 李四, 天津市西青区宾水西道391号 ; public Form1() InitializeComponent(); private void listView1_SelectedIndexChanged(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e) listView1.View = View.Details; listView1.Colu
12、mns.Add(序号,50,HorizontalAlignment.Center); listView1.Columns.Add(学号, 80, HorizontalAlignment.Center); listView1.Columns.Add(姓名, 80, HorizontalAlignment.Center); listView1.Columns.Add(地址,290, HorizontalAlignment.Center); ListViewItem lvi = new ListViewItem(data1); listView1.Items.Add(lvi); lvi = new
13、ListViewItem(data2); listView1.Items.Add(lvi); private void listView1_Click(object sender, EventArgs e) textBox1.Text = listView1.SelectedItems0.SubItems1.Text; textBox2.Text = listView1.SelectedItems0.SubItems2.Text; textBox3.Text = listView1.SelectedItems0.SubItems3.Text; 运行结果:5、 控件综合应用(1)创建一个登录窗体
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 天津 理工大学 C# 实验 15

限制150内