.NET编程技术实验报告

上传人:1888****888 文档编号:36834126 上传时间:2021-11-01 格式:DOC 页数:27 大小:806.35KB
收藏 版权申诉 举报 下载
.NET编程技术实验报告_第1页
第1页 / 共27页
.NET编程技术实验报告_第2页
第2页 / 共27页
.NET编程技术实验报告_第3页
第3页 / 共27页
资源描述:

《.NET编程技术实验报告》由会员分享,可在线阅读,更多相关《.NET编程技术实验报告(27页珍藏版)》请在装配图网上搜索。

1、 实验报告 (2012-2013学年第二学期) 课程名称: .NET编程技术 学生姓名: 兰天翔 专业班级: 10级计算机2班 学 院: 信电学院 学 号: 14514026 学生成绩: 实验一Windows应用编程实验目的1 掌握windows窗体的基本属性、事件和方法的使用。2 掌握常用控件的具体使用。实验内容完成字体设置程序。实验代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Te

2、xt;using System.Windows.Forms;namespace FontSet public partial class Form1 : Form string fontFamily=宋体; float fontSize=10.0f; FontStyle fontStyle=FontStyle.Regular; public Form1() InitializeComponent(); private void setFont() this.richTextBox1.Font = new Font(fontFamily, fontSize, fontStyle); privat

3、e void rbSongti_CheckedChanged(object sender, EventArgs e) if (rbSongti.Checked) this.fontFamily = 宋体; setFont(); private void rbLishu_CheckedChanged(object sender, EventArgs e) if (rbLishu.Checked) this.fontFamily = 隶书; setFont(); private void cbBold_CheckedChanged(object sender, EventArgs e) if (c

4、bBold.Checked) this.fontStyle = this.fontStyle| FontStyle.Bold; else this.fontStyle -= FontStyle.Bold; setFont(); private void cbItalic_CheckedChanged(object sender, EventArgs e) if (cbItalic.Checked) this.fontStyle =this.fontStyle| FontStyle.Italic; else this.fontStyle -= FontStyle.Italic; setFont(

5、); private void cbUnderline_CheckedChanged(object sender, EventArgs e) if (cbUnderline.Checked) this.fontStyle = this.fontStyle | FontStyle.Underline; else this.fontStyle -= FontStyle.Underline; setFont(); private void numericUpDown1_ValueChanged(object sender, EventArgs e) this.fontSize = Convert.T

6、oSingle(this.numericUpDown1.Value); setFont(); Programusing System;using System.Collections.Generic;using System.Windows.Forms;namespace FontSet static class Program / 应用程序的主入口点。 STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Appl

7、ication.Run(new Form1(); Forml.Designernamespace FontSet partial class Form1 / 必需的设计器变量。 private System.ComponentModel.IContainer components = null; / 清理所有正在使用的资源。 / 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null) components.Dispose();

8、 base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改此方法的内容。 private void InitializeComponent() this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.rbSongti

9、 = new System.Windows.Forms.RadioButton(); this.rbLishu = new System.Windows.Forms.RadioButton(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.cbBold = new System.Windows.Forms.CheckBox(); this.cbItalic = new System.Windows.Forms.CheckBox(); this.cbUnderline = new System.Wind

10、ows.Forms.CheckBox(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); (System.ComponentModel.ISupportInitialize)(this.numericUpDown1).BeginInit(); this.SuspendLayout(); / groupBox1 this.groupB

11、ox1.Controls.Add(this.rbLishu); this.groupBox1.Controls.Add(this.rbSongti); this.groupBox1.Location = new System.Drawing.Point(3, 206); this.groupBox1.Name = groupBox1; this.groupBox1.Size = new System.Drawing.Size(208, 199); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox

12、1.Text = 字体; / groupBox2 this.groupBox2.Controls.Add(this.numericUpDown1); this.groupBox2.Location = new System.Drawing.Point(217, 206); this.groupBox2.Name = groupBox2; this.groupBox2.Size = new System.Drawing.Size(201, 199); this.groupBox2.TabIndex = 0; this.groupBox2.TabStop = false; this.groupBo

13、x2.Text = 大小; / groupBox3 this.groupBox3.Controls.Add(this.cbUnderline); this.groupBox3.Controls.Add(this.cbItalic); this.groupBox3.Controls.Add(this.cbBold); this.groupBox3.Location = new System.Drawing.Point(424, 206); this.groupBox3.Name = groupBox3; this.groupBox3.Size = new System.Drawing.Size(

14、216, 199); this.groupBox3.TabIndex = 0; this.groupBox3.TabStop = false; this.groupBox3.Text = 风格; / rbSongti this.rbSongti.AutoSize = true; this.rbSongti.Location = new System.Drawing.Point(27, 41); this.rbSongti.Name = rbSongti; this.rbSongti.Size = new System.Drawing.Size(47, 16); this.rbSongti.Ta

15、bIndex = 0; this.rbSongti.TabStop = true; this.rbSongti.Text = 宋体; this.rbSongti.UseVisualStyleBackColor = true; this.rbSongti.CheckedChanged += new System.EventHandler(this.rbSongti_CheckedChanged); / rbLishu this.rbLishu.AutoSize = true; this.rbLishu.Location = new System.Drawing.Point(27, 81); th

16、is.rbLishu.Name = rbLishu; this.rbLishu.Size = new System.Drawing.Size(47, 16); this.rbLishu.TabIndex = 1; this.rbLishu.TabStop = true; this.rbLishu.Text = 隶书; this.rbLishu.UseVisualStyleBackColor = true; this.rbLishu.CheckedChanged += new System.EventHandler(this.rbLishu_CheckedChanged); / numericU

17、pDown1 this.numericUpDown1.Location = new System.Drawing.Point(36, 52); this.numericUpDown1.Name = numericUpDown1; this.numericUpDown1.Size = new System.Drawing.Size(120, 21); this.numericUpDown1.TabIndex = 2; this.numericUpDown1.Value = new decimal(new int 10, 0,0, 0); this.numericUpDown1.ValueChan

18、ged += new System.EventHandler(this.numericUpDown1_ValueChanged); / cbBold this.cbBold.AutoSize = true; this.cbBold.Location = new System.Drawing.Point(50, 41); this.cbBold.Name = cbBold; this.cbBold.Size = new System.Drawing.Size(48, 16); this.cbBold.TabIndex = 3; this.cbBold.Text = 粗体; this.cbBold

19、.UseVisualStyleBackColor = true; this.cbBold.CheckedChanged += new System.EventHandler(this.cbBold_CheckedChanged); / cbItalic this.cbItalic.AutoSize = true; this.cbItalic.Location = new System.Drawing.Point(50, 81); this.cbItalic.Name = cbItalic; this.cbItalic.Size = new System.Drawing.Size(48, 16)

20、; this.cbItalic.TabIndex = 4; this.cbItalic.Text = 斜体; this.cbItalic.UseVisualStyleBackColor = true; this.cbItalic.CheckedChanged += new System.EventHandler(this.cbItalic_CheckedChanged); / cbUnderline this.cbUnderline.AutoSize = true; this.cbUnderline.Location = new System.Drawing.Point(50, 121); t

21、his.cbUnderline.Name = cbUnderline; this.cbUnderline.Size = new System.Drawing.Size(60, 16); this.cbUnderline.TabIndex = 5; this.cbUnderline.Text = 下划线; this.cbUnderline.UseVisualStyleBackColor = true; this.cbUnderline.CheckedChanged += new System.EventHandler(this.cbUnderline_CheckedChanged); / ric

22、hTextBox1 this.richTextBox1.Location = new System.Drawing.Point(0, 0); this.richTextBox1.Name = richTextBox1; this.richTextBox1.Size = new System.Drawing.Size(640, 200); this.richTextBox1.TabIndex = 1; this.richTextBox1.Text = ; / Form1 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); t

23、his.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(641, 404); this.Controls.Add(this.richTextBox1); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = Form1; this.Text = Form1; this.

24、groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); (System.ComponentModel.ISupportInitialize)(this.numericUpDown1).EndInit(); this.ResumeLayout(false); #endregion private System.Window

25、s.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.RadioButton rbLishu; private System.Windows.Forms.RadioButton rbSongti; private System.Windows.Forms.NumericUpDown numericUpDown1; private System

26、.Windows.Forms.CheckBox cbUnderline; private System.Windows.Forms.CheckBox cbItalic; private System.Windows.Forms.CheckBox cbBold; private System.Windows.Forms.RichTextBox richTextBox1; 实验二 图形图像编程实验目的1 掌握Graphics类。2 掌握基本的绘图方法。3 掌握图像的显示和处理方法。实验内容完成画板应用。在窗体的空白处绘图,并将图片保存起来。实验代码:using System;using Syste

27、m.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Windraw public partial class Form1 : Form Graphics dc; Bitmap bmp = new Bitmap(800, 800); Point p0; Point p1; bool isPress = false; public Form1() Initializ

28、eComponent(); dc = Graphics.FromImage(bmp); private void button1_Click(object sender, EventArgs e) this.saveFileDialog1.Filter = BMP图片|*.bmp; if (this.saveFileDialog1.ShowDialog() = DialogResult.OK) this.bmp.Save(this.saveFileDialog1.FileName); private void drawImage() if (isPress) dc.DrawLine(Pens.

29、Red, p0, p1); this.pictureBox1.Image = bmp; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) p0 = e.Location; isPress = true; private void pictureBox1_MouseMove(object sender, MouseEventArgs e) p1 = e.Location; drawImage(); p0 = p1; private void pictureBox1_MouseUp(object sender,

30、MouseEventArgs e) p1 = e.Location; drawImage(); isPress = false; Program:using System;using System.Collections.Generic;using System.Windows.Forms;namespace Windraw static class Program / 应用程序的主入口点。 STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingD

31、efault(false); Application.Run(new Form1(); Forml .designernamespace Windraw partial class Form1 / 必需的设计器变量。 private System.ComponentModel.IContainer components = null; / 清理所有正在使用的资源。 / 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null) c

32、omponents.Dispose(); base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改此方法的内容。 private void InitializeComponent() this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.button1 = new System.Windows.Forms.Button(); this.saveFileDialog1 = new System.Windows.Forms

33、.SaveFileDialog(); (System.ComponentModel.ISupportInitialize)(this.pictureBox1).BeginInit(); this.SuspendLayout(); / pictureBox1 this.pictureBox1.BackColor = System.Drawing.Color.White; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = pictureBox1; this.pictureBox1.

34、Size = new System.Drawing.Size(517, 361); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_M

35、ouseMove); this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp); / button1 this.button1.Location = new System.Drawing.Point(0, 367); this.button1.Name = button1; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.T

36、ext = 保存; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); / Form1 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(517,

37、 392); this.Controls.Add(this.button1); this.Controls.Add(this.pictureBox1); this.Name = Form1; this.Text = Form1; (System.ComponentModel.ISupportInitialize)(this.pictureBox1).EndInit(); this.ResumeLayout(false); #endregion private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.

38、Forms.Button button1; private System.Windows.Forms.SaveFileDialog saveFileDialog1; 实验三 数据库编程实验目的1 理解ADO.NET对象模型。2 熟悉常用数据邦定控件的使用方法。实验内容完成简单学生信息系统,能够查询学生信息,增、删、改学生信息。实验代码:Formlusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.

39、Text;using System.Windows.Forms;using System.Data.SqlClient;namespace WinStuDB public partial class Form1 : Form SqlHelper helper = new SqlHelper(); public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) DataSet ds; /ds=helper.SelectSqlReturnDataSet(select * from s

40、tudent); /string cmdText = select * from student where ssex=ssex and sno=sno; /string ssex; /ssex = 男; /string sno; /sno = 1; /SqlParameter pars = new SqlParameter / / new SqlParameter(ssex,ssex), / new SqlParameter(sno,sno) /; /ds = helper.SelectSqlReturnDataSet(cmdText, pars, CommandType.Text); ds

41、 = helper.SelectSqlReturnDataSet(select * from student, null, CommandType.Text); this.dataGridView1.DataSource = ds.Tables0; private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) /this.dataGridView1.CurrentRow.Selected = true; bindData(); private void btAdd_Click(object se

42、nder, EventArgs e) string sql = insert into student(sno,sname,ssex) values ( sno, sname, ssex); SqlParameter pars= new SqlParameter new SqlParameter(sno,tbSno.Text), new SqlParameter(sname,tbSname.Text), new SqlParameter(ssex,tbSsex.Text) ; int count = helper.ExecuteSQLReturnInt(sql, pars, CommandTy

43、pe.Text); if (count 0) this.dataGridView1.DataSource = helper.SelectSqlReturnDataSet(select * from student).Tables0; MessageBox.Show(添加成功); private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) if (MessageBox.Show(是否删除, 删除确认, MessageBoxButtons.OKCancel) = DialogResul

44、t.OK) string sno = this.dataGridView1.CurrentRow.Cellssno.Value.ToString(); string cmdText = delete from student where sno=sno; SqlParameter pars = new SqlParameter new SqlParameter(sno,sno); int count = helper.ExecuteSQLReturnInt(cmdText, pars, CommandType.Text); if (count 0) this.dataGridView1.Dat

45、aSource = helper.SelectSqlReturnDataSet(select * from student).Tables0; MessageBox.Show(删除成功); private void bindData() this.tbSno.Text = this.dataGridView1.CurrentRow.Cellssno.Value.ToString(); this.tbSname.Text = this.dataGridView1.CurrentRow.Cellssname.Value.ToString() ; this.tbSsex.Text = this.da

46、taGridView1.CurrentRow.Cellsssex.Value.ToString(); private void btUpdate_Click(object sender, EventArgs e) string sno = this.dataGridView1.CurrentRow.Cellssno.Value.ToString(); string cmdText = update student set sname=sname,ssex=ssex where sno=sno; SqlParameter pars = new SqlParameter new SqlParame

47、ter(sno,sno), new SqlParameter(sname,this.tbSname.Text), new SqlParameter(ssex,this.tbSsex.Text) ; int count = helper.ExecuteSQLReturnInt(cmdText, pars, CommandType.Text); if (count 0) this.dataGridView1.DataSource = helper.SelectSqlReturnDataSet(select * from student).Tables0; MessageBox.Show(更新成功); Forml.Designernamespace WinStuDB partial class Form1 / 必需的设计器变量。 private System.ComponentModel.IContainer components = null; /

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!