.NET编程技术实验报告_第1页
.NET编程技术实验报告_第2页
.NET编程技术实验报告_第3页
.NET编程技术实验报告_第4页
.NET编程技术实验报告_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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, commandtype.text); if (count 0) this.datagridview1.datasource = helper.selectsqlreturndataset(select * from student).tables0; messagebox.show(添加成功); private void datagridview1_celldoubleclick(object sender, datagrid

温馨提示

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

评论

0/150

提交评论