c#-可视化实验

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

可视化程序设计实验报告班级:学号:姓名:东北大学秦皇岛分校计算机与通信工程学院2017.12实验1:简单的计算器:程序代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Navigation;usingSystem.Windows.Shapes;namespaceshiyan{///summary///Window1.xaml的交互逻辑////summarypublicpartialclassWindow1:Window{publicWindow1(){InitializeComponent();}floattemp1=-1;intpos=0;publicvoidaddNum(intnum){textBox1.Text=textBox1.Text+num.ToString();}privatevoidbutton1_Click(objectsender,RoutedEventArgse){addNum(1);}privatevoidbutton2_Click(objectsender,RoutedEventArgse){addNum(2);}privatevoidbutton3_Click(objectsender,RoutedEventArgse){addNum(3);}privatevoidbutton4_Click(objectsender,RoutedEventArgse){addNum(4);}privatevoidbutton5_Click(objectsender,RoutedEventArgse){addNum(5);}privatevoidbutton6_Click(objectsender,RoutedEventArgse){addNum(6);}privatevoidbutton7_Click(objectsender,RoutedEventArgse){addNum(7);}privatevoidbutton8_Click(objectsender,RoutedEventArgse){addNum(8);}privatevoidbutton9_Click(objectsender,RoutedEventArgse){addNum(9);}privatevoidbutton10_Click(objectsender,RoutedEventArgse){pos=1;temp1=Convert.ToInt64(textBox1.Text);textBox1.Text=;}privatevoidbutton11_Click(objectsender,RoutedEventArgse){pos=2;temp1=Convert.ToInt64(textBox1.Text);textBox1.Text=;}privatevoidbutton12_Click(objectsender,RoutedEventArgse){floattemp2=Convert.ToInt64(textBox1.Text);switch(pos){case1:textBox1.Text=(temp1+temp2).ToString();break;case2:textBox1.Text=(temp1+temp2).ToString();break;}}privatevoidbutton13_Click(objectsender,RoutedEventArgse){textBox1.Text=0;temp1=0;pos=0;}privatevoidtextBox1_TextChanged(objectsender,TextChangedEventArgse){}}}运行截图:输入30+40的结果显示:实验2:一个简单的记事本,具有打开和保存的功能。程序代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespaceshiyan1{publicpartialclassForm2:Form{publicForm2(){InitializeComponent();}privatevoidForm2_Load(objectsender,EventArgse){Text=无标题-我的记事本;}privatestringOriginalContent;privatestring_FileName=;publicstringFileName{get{return_FileName;}set{_FileName=value;Text=Path.GetFileName(value)+-我的记事本;}}privatevoid打开ToolStripMenuItem_Click(objectsender,EventArgse){OpenFileDialogop=newOpenFileDialog();//stringpath=;if(op.ShowDialog()==DialogResult.OK){FileName=op.FileName;try{OriginalContent=File.ReadAllText(FileName);richTextBox1.Text=OriginalContent;}catch{}}}privatevoid保存ToolStripMenuItem_Click(objectsender,EventArgse){SaveFileDialogsv=newSaveFileDialog();boolShouldSave=false;if(FileName!=){if(sv.ShowDialog()==DialogResult.OK)ShouldSave=true;if(ShouldSave){try{File.WriteAllText(FileName,richTextBox1.Text);OriginalContent=richTextBox1.Text;}catch(Exception){throw;}}}}privatevoidrichTextBox1_TextChanged(objectsender,EventArgse){}}}运行截图:保存和打开:实验3:做一个程序,可以读取一个位图并显示,通过点击上下左右按钮,可以调整图片的位置,通过点击放大缩小,可以缩放图片程序代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceshiyan2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();pictureBox1.Height=100;pictureBox1.Width=150;}privatevoidbutton1_Click(objectsender,EventArgse){pictureBox1.Top-=60;}privatevoidbutton2_Click(objectsender,EventArgse){pictureBox1.Left-=30;}privatevoidbutton3_Click(objectsender,EventArgse){pictureBox1.Height+=60;pictureBox1.Width+=60;}privatevoidbutton4_Click(objectsender,EventArgse){pictureBox1.Height-=60;pictureBox1.Width-=60;}privatevoidbutton5_Click(objectsender,EventArgse){pictureBox1.Left+=90;}privatevoidbutton6_Click(objectsender,EventArgse){pictureBox1.Top+=30;}privatevoid读取ToolStripMenuItem_Click(objectsender,EventArgse){OpenFileDialogofd=newOpenFileDialog();ofd.Filter=*.jpg|*.jpg;if(ofd.ShowDialog()==DialogResult.OK){stringfname=ofd.FileName;Bitmapbitmap=newBitmap(fname);pictureBox1.Image=bitmap;}}}}运行截图:实验4:做一张表。具有添加学好、姓名;查询和保存的功能。程序代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespaceshiyan4{publicpartialclassForm1:Form{SqlDataAdapteradapter;DataTabletable;publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){stringconnStr=Properties.Settings.Default.Database1ConnectionString;SqlConnectionconn=newSqlConnection(connStr);stringname=select*fromStudentwherename=+'+textBox1.Text+';SqlDataAdapteradapter2;adapter2=newSqlDataAdapter(name,conn);DataTabletable2=newDataTable();adapter2.Fill(table2);dataGridView1.DataSource=table2;}privatevoidForm1_Load(objectsender,EventArgse){stringconnStr=Properties.Settings.Default.Database1ConnectionString;SqlConnectionconn=newSqlConnection(connStr);adapter=newSqlDataAdapter(select*from

1 / 15
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功