版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、可视化程序设计实验报告学 号:2143214姓 名:李子厚提交日期:2016-11-1成 绩:东北大学秦皇岛分校可视化程序设计 实验报告实验一 控件和窗体【实验内容】做一个简单的小计算器,实现整数的加减法【关键代码】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 Window
2、sFormsApplication1 public partial class Form1 : Form double outValue = 0; bool c = false; string d; bool f = true; int x = 0; int y = 0; public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) caculate(1); private void button2_Click(object sender, EventArgs e) ca
3、culate(2); private void button3_Click(object sender, EventArgs e) caculate(3); private void button4_Click(object sender, EventArgs e) caculate(4); private void button5_Click(object sender, EventArgs e) caculate(5); private void button6_Click(object sender, EventArgs e) caculate(6); private void butt
4、on7_Click(object sender, EventArgs e) caculate(7); private void button8_Click(object sender, EventArgs e) caculate(8); private void button9_Click(object sender, EventArgs e) caculate(9); private void button14_Click(object sender, EventArgs e) caculate(0); private void button10_Click(object sender, E
5、ventArgs e) c = true; d = "+" textBox1.Text += "+" private void button11_Click(object sender, EventArgs e) c = true; d = "-" textBox1.Text += "-" private void button12_Click(object sender, EventArgs e) switch (d) case "+": outValue = x + y; break; ca
6、se "-": outValue = x - y; break; case "*": outValue = x * y; break; case "/": outValue = x /y; break; textBox1.Text = outValue + "" c = false; f = false; x = 0; y = 0; private void button13_Click(object sender, EventArgs e) textBox1.Text = "" c = fal
7、se; f = false; x = 0; y = 0; public void caculate(int z) if (f = false) textBox1.Text = "" f = true; if (c = true) textBox1.Text += z; y = 10 * y + z; else textBox1.Text += z; x = 10 * x + z; private void button15_Click(object sender, EventArgs e) if (c = true) y = 0; textBox1.Text = x + d
8、; else x = 0; textBox1.Text = "" private void button17_Click(object sender, EventArgs e) c = true; d = "*" textBox1.Text += "*" private void button16_Click(object sender, EventArgs e) c = true; d = "/" textBox1.Text += "/" private void button18_Click
9、(object sender, EventArgs e) /除法功能只能算整除,由于不知道int换成double怎么改所以没能实现【程序截图】实验二 目录与文件【实验内容】做一个简单的记事本,有打开和保存功能【关键代码】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
10、.Windows.Forms;using System.IO;namespace test2 public partial class Form1 : Form public Form1() InitializeComponent(); string filename; private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog open = new OpenFileDialog(); filename = open.FileName; open.Filter = "txt fil
11、es (*.txt)|*.txt|All files (*.*)|*.*" open.FilterIndex = 2; open.RestoreDirectory = true; if (open.ShowDialog()=DialogResult.OK) StreamReader reader = new StreamReader(open.FileName, System.Text.Encoding.Default); richTextBox1.Text = reader.ReadToEnd(); reader.Close(); private void 保存ToolStripM
12、enuItem_Click(object sender, EventArgs e) SaveFileDialog save = new SaveFileDialog(); StreamWriter writer; save.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" save.FilterIndex = 2; save.RestoreDirectory = true; if (save.ShowDialog() = DialogResult.OK) writer = new StreamWriter(save
13、.FileName); writer.Write(richTextBox1.Text); /写入 writer.Close();/关闭流 【程序截图】实验三 图形图像处理【实验内容】做一个程序,可以读取一个位图并显示,通过点击上下左右按钮,可以调整图片的位置,通过点击放大缩小,可以缩放图片。【关键代码】using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text
14、;using System.Windows.Forms;namespace WindowsFormsApplication3 public partial class Form1 : Form Graphics g; int width, height; int x, y; const int per = 5; float rit = 1; public Form1() InitializeComponent(); width = pictureBox1.Width; height = pictureBox1.Height; g = this.pictureBox1.CreateGraphic
15、s(); x = y = 0; private void draw() g = this.pictureBox1.CreateGraphics(); g.Clear(this.BackColor); g.TranslateTransform(x, y); g.ScaleTransform(rit, rit); g.DrawImage(pictureBox1.Image, 0, 0, width, height); private void 读取ToolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog open = ne
16、w OpenFileDialog(); open.Filter = "image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*" if (open.ShowDialog() = DialogResult.OK) pictureBox1.Image = Image.FromFile(open.FileName); private void pictureBox1_Click(object sender, EventArgs e) private void button1_Click(object
17、sender, EventArgs e) y = y - per; draw(); private void button2_Click(object sender, EventArgs e) y = y + per; draw(); private void button3_Click(object sender, EventArgs e) x = x - per; draw(); private void button4_Click(object sender, EventArgs e) x = x + per; draw(); private void button5_Click(obj
18、ect sender, EventArgs e) rit = (float)(rit + 0.1); draw(); private void button6_Click(object sender, EventArgs e) if (rit > 0) rit = (float)(rit - 0.1); draw(); 【程序截图】 实验四 数据操作【实验内容】制作一个程序,输入一个姓名,点击查询。【关键代码】using System;using System.Collections.Generic;using System.ComponentModel;using System.Dat
19、a;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace DBOperate public partial class Form1 : Form SqlDataAdapter adapter; DataTable table; DataSet dataset1; public Form1() InitializeComponent(); privat
20、e void Form1_Load(object sender, EventArgs e) string connStr = Properties.Settings.Default.Database2ConnectionString;/连接字符串 SqlConnection conn = new SqlConnection(connStr);/建立到数据库的连接 adapter = new SqlDataAdapter("select * from Table", conn); SqlCommandBuilder builder = new SqlCommandBuilde
21、r(adapter); adapter.InsertCommand = builder.GetInsertCommand(); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); table = new DataTable(); adapter.Fill(table); dataGridView1.DataSource = table; private void button2_Click(object sender, EventArgs
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026甘肃定西临洮县文庙巷社区卫生服务中心招聘卫生专业技术人员5人备考题库及答案详解(夺冠)
- 2026湖南怀化市辰溪县供销合作联合社见习生招聘1人备考题库附答案详解(模拟题)
- 2026湖北事业单位联考监利市招聘178人备考题库及答案详解(夺冠)
- 2026河南新乡市金瀚学校教师招聘19人备考题库附答案详解(a卷)
- 2026海南海口市纪委监委所属事业单位招聘4人备考题库(第一号)附答案详解(培优a卷)
- 2026重庆大学机械与运载工程学院郑玲教授研究团队博士后招聘备考题库含答案详解(b卷)
- 2026湖南怀化市辰溪县住房保障服务中心见习招聘2人备考题库含答案详解(典型题)
- 2026河北唐山古冶爱然医院招聘备考题库带答案详解(新)
- 2026福建南安市霞美镇中心幼儿园钟育分园春季招聘备考题库附答案详解(黄金题型)
- 2026湖北武汉东风汽车集团股份有限公司采购管理部招聘5人备考题库附答案详解(综合题)
- DB37-T 4704-2024 健康体检机构建设与服务规范
- 《小米智能家居》课件
- 建筑施工安全技术操作规程
- 高校绿色金融人才培养模式与机制探索
- NB/T 11446-2023煤矿连采连充技术要求
- 竣工资料编制计划
- 北京石油化工学院大一高等数学上册期末考试卷及答案
- GB/T 13077-2024铝合金无缝气瓶定期检验与评定
- 基坑工程安全风险辨识
- GB/T 43780-2024制造装备智能化通用技术要求
- DB4201-T 575-2019 武汉市环境卫生作业规范
评论
0/150
提交评论