窗体及控件程序设计_第1页
窗体及控件程序设计_第2页
窗体及控件程序设计_第3页
窗体及控件程序设计_第4页
窗体及控件程序设计_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

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

文档简介

1、河南城建学院计算机科学与工程系c#语言windows程序设计实验报告实验名称:窗体及控件程序设计成绩专业班级:信息管理与信息系统姓名:赵文普学号:083411151实验日期:2013 年10 月 日软件环境:开发工具:硬件环境:硬盘:内存:一、实验目的(1) 掌握c#窗体创建及其常用控件的选用和编程。(2) 进一步提高编程能力,掌握对c#方法的调用及其参数类型的设置。(3) 练习简单应用程序的规划设计及其程序开发的方法。二、实验内容(1)设计一个简易计算器,包括0,1,2,3,4,5,6,7,8,9,+-*/二十六个按钮通过一个文木框,显示输出的结果。三、实验数据using system;us

2、ing system. collections generic;using system. componenthodel;using systemdala;using system drawing;using system .text;using system .windows .forms;namespace计算器public partial class form 1 : formpublic form i ()initializecomponento;string stro = strl = "0", result = ",str2=""d

3、ouble pl=0, p2=0;if (strl =hot,) strl = ,tr,;else strl = strl + m1"this.textbox l.text =str2+str 1;private void button2_click(objcct sender, event args c) if (strl =,0") strl = "2"else strl = sirl + "2”;this.textbox l.text = str2 + strl;private void button3_ciick(object send

4、er, eventargs e)if (strl =n0h)strl = h3n;else strl = strl + n3n;this.tcxtbox l.text = str2 + strl;private void button5_click(objcct sender, eventargs c) if (strl =”()“)str 1 = "4”;else strl = sirl + ,f4h;this.textbox l.text = str2 + strl;private void button6_click(object sender, eventargs e)if

5、(strl = h0n) strl =m5h;elsestrl =strl + "5h;this.text box l.text = str2 + strl;private void button 7_click(objcct sender, event args c) if (strl =,0") strl = ,6n;elsesirl =strl + ,6"this.textboxl.lext = str2 + strl;private void button9_click(object sender, eventargs e) if (strl =”0”)s

6、u7“;elsestrl =strl + ,7h;this.tcxtbox l.lcxt = str2 + strl;private void button 10_click(objcct sender, eventargs c) if (strl =,0") strl = ,8n;elsestrl =strl + h8m;this.textboxl.lext = str2 + strl;if (str 1 =hoh)strl = n9h;elsestrl 二 strl +”9”;this.text box l.text = str2 + strl;private void butt

7、on 13_click(objcct sender, eventargs c) if (strl =,o',)strl = "0"elsestrl = strl + "0"this.textboxl.text = str2 + strl;private void button 14_click(object sender, eventargs e) strl =strl + ".n;this.textboxl.text = str2 + strl;this.button 14.enablcd = false;private void b

8、utton4_click(object sender, eventargs e) pl = convert.lodouble(this.textbox 1 .text);stro = this.button4.tcxt;str2 = pl + stro;strl = "0"this.button 15.enabled = true;this.textboxl.text = str2;this.button 14.enabied = true;this-button4.enabled = false;this,button8.enabled = false;this.butt

9、on 12.enabled = false;this.button 16.enabled = false;pl = convert.lbdouble(this.textbox 1 .text); stro = this.button8.lext;str2 = pl + stio;strl = ”0”;this.button 15.enabled = true;this.textboxl.text = str2;this.button 14.enabied = true ; this.button4.enablcd = false; thisbutton&enabled = false;

10、this.button 12.enablcd = false;this.button 16.enabled = false;private void button 12_click(object sender, event args e) pl = convert.t()double(this.textbox 1 .text);stro = this.button 12.1ext;str2 = pl + stro;strl = ”0”;this.button 15.enabled = true;this.textbox l.text = str2;this.button 14.enabled

11、= true ;this.button4.enablcd = false;this.buttons.enablcd = false;this.button 12.enabled = false;this.button 16.enabled = false;private void button 16_click(objcct sender, evcntargs c) pl = con vert.lbdouble(this.textbox 1 .text);stro = this.bullonl6.lext;str2 = pl + stro;strl = ”0”;this.button 15.e

12、nabled = true;this.textboxl.text = str2;this.button 14.enabled = true ;this.button4.enabled = false;this.buttons.enabled = false;this.button 12.enabled = false;this.button 16.enabied = false;private void button 15_click(object sender, eventargs e)p2 = convert.lbdouble(strl);switch (stro) case”+”:res

13、ult = con vcrt.1bstring(p 1 + p2);break;caseresult = convert.lostringcp 1 p2);break;caseresult = convert.lostring(p 1 * p2);break;case ”/”:if (p2 1= 0)resu it = converttbstring(pl / p2);elseresult ="无意义"break;this.tcxtboxl .text = con vert.tostring(p 1) + stio + convert.tostring(p2) + m=m

14、+ result;this.button 1 .enabled =false;this.button2.enabled =false;this.button3.enabled =false;this.button4.enabled = false;this.button5.enabled =false;this.button6.enabled =false;this.button7.enabled =false;this.button8.enablcd = false;th is.button9.en abled =false;this.button 10.enablcd =false;th

15、is.button 11.enabled =false;this.button 12.enablcd = false;this.button 13.enabled =false;this.button 14.en abled =false;this.button 15.enabled =false;this.button 16.enabled = false;private void button 17_cliek(object sender, eventargs e)stro = strl = “o”; result 二"“;str2 = ”;pl = 0; p2 = 0;this

16、.textboxl.lext = "0"this.button 1 .enabled = true; this.button2.enabled = true; this.button3.enabled = true;this.button4.enabled =true;this.button5.enabled=true;this.button6.enab!ed =true; this.button7.enabled=true;this.button8.enabled =true;this.button9.enabled=true;this.button lo.enab le

17、d =tine;this.button 11.enabled=tine;this.button 12.enabled =tme;this.button 13.enabled=true;this.button 14.enabled =true;this.button 15.enab led=false;this.button 16.enabled =true;private void button 18_click(objcct sender, eventargs c) this.close();1)计算器7812457118:0重晋关闭计算器78*9四、岀现问题及解决方案在编写程序的过程屮,输入必须按格式才能进行。如果格式错误,程序无法进行,为了解决这一问题采用了控件可见不可见。问题1开始的时候不能直接按等于。问题2小说点,加减乘除的使用不能连续

温馨提示

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

评论

0/150

提交评论