using system; using system.drawing; using system.windows; using system.windows.forms; using system.collections; using system.componentmodel; using system.data;
#region 各控件的属性的方法windows form designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void initializecomponent() { system.resources.resourcemanager resources = new system.resources.resourcemanager(typeof(form1)); this.txtshow = new system.windows.forms.textbox(); this.groupbox1 = new system.windows.forms.groupbox(); this.c = new system.windows.forms.button(); this.ce = new system.windows.forms.button(); this.btn_rev = new system.windows.forms.button(); this.btn_dot = new system.windows.forms.button(); this.btn_add = new system.windows.forms.button(); this.btn_equ = new system.windows.forms.button(); this.btn_sign = new system.windows.forms.button(); this.btn_sub = new system.windows.forms.button(); this.btn_mul = new system.windows.forms.button(); this.btn_0 = new system.windows.forms.button(); this.btn_3 = new system.windows.forms.button(); this.btn_2 = new system.windows.forms.button(); this.btn_1 = new system.windows.forms.button(); this.btn_6 = new system.windows.forms.button(); this.btn_5 = new system.windows.forms.button(); this.btn_4 = new system.windows.forms.button(); this.btn_sqrt = new system.windows.forms.button(); this.btn_div = new system.windows.forms.button(); this.btn_7 = new system.windows.forms.button(); this.btn_8 = new system.windows.forms.button(); this.btn_9 = new system.windows.forms.button(); this.btn_sqr = new system.windows.forms.button(); this.mainmenu1 = new system.windows.forms.mainmenu(); this.menuitem1 = new system.windows.forms.menuitem(); this.menuitem2 = new system.windows.forms.menuitem(); this.menuitem3 = new system.windows.forms.menuitem(); this.menuitem4 = new system.windows.forms.menuitem(); this.menuitem5 = new system.windows.forms.menuitem(); this.menuitem6 = new system.windows.forms.menuitem(); this.menuitem8 = new system.windows.forms.menuitem(); this.menuitem9 = new system.windows.forms.menuitem(); this.menuitem10 = new system.windows.forms.menuitem(); this.groupbox1.suspendlayout(); this.suspendlayout(); // // txtshow // this.txtshow.backcolor = system.drawing.color.fromargb(((system.byte)(192)), ((system.byte)(192)), ((system.byte)(255))); this.txtshow.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.point, ((system.byte)(134))); this.txtshow.forecolor = system.drawing.color.purple; this.txtshow.location = new system.drawing.point(25, 8); this.txtshow.name = "txtshow"; this.txtshow.size = new system.drawing.size(228, 23); this.txtshow.tabindex = 1; this.txtshow.text = "0."; this.txtshow.textalign = system.windows.forms.horizontalalignment.right; // // groupbox1 // this.groupbox1.controls.add(this.c); this.groupbox1.controls.add(this.ce); this.groupbox1.controls.add(this.btn_rev); this.groupbox1.controls.add(this.btn_dot); this.groupbox1.controls.add(this.btn_add); this.groupbox1.controls.add(this.btn_equ); this.groupbox1.controls.add(this.btn_sign); this.groupbox1.controls.add(this.btn_sub); this.groupbox1.controls.add(this.btn_mul); this.groupbox1.controls.add(this.btn_0); this.groupbox1.controls.add(this.btn_3); this.groupbox1.controls.add(this.btn_2); this.groupbox1.controls.add(this.btn_1); this.groupbox1.controls.add(this.btn_6); this.groupbox1.controls.add(this.btn_5); this.groupbox1.controls.add(this.btn_4); this.groupbox1.controls.add(this.btn_sqrt); this.groupbox1.controls.add(this.btn_div); this.groupbox1.controls.add(this.btn_7); this.groupbox1.controls.add(this.btn_8); this.groupbox1.controls.add(this.btn_9); this.groupbox1.controls.add(this.btn_sqr); this.groupbox1.location = new system.drawing.point(24, 40); this.groupbox1.name = "groupbox1"; this.groupbox1.size = new system.drawing.size(232, 184); this.groupbox1.tabindex = 21; this.groupbox1.tabstop = false; this.groupbox1.text = "计算机区"; // // c // this.c.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.c.forecolor = system.drawing.color.red; this.c.location = new system.drawing.point(178, 48); this.c.name = "c"; this.c.size = new system.drawing.size(36, 61); this.c.tabindex = 41; this.c.text = "c"; this.c.click += new system.eventhandler(this.btn_oper); // // ce // this.ce.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.ce.forecolor = system.drawing.color.red; this.ce.location = new system.drawing.point(138, 16); this.ce.name = "ce"; this.ce.size = new system.drawing.size(76, 29); this.ce.tabindex = 40; this.ce.text = "ce"; this.ce.click += new system.eventhandler(this.btn_oper); // // btn_rev // this.btn_rev.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_rev.forecolor = system.drawing.color.blue; this.btn_rev.location = new system.drawing.point(178, 112); this.btn_rev.name = "btn_rev"; this.btn_rev.size = new system.drawing.size(36, 29); this.btn_rev.tabindex = 39; this.btn_rev.text = "1/x"; this.btn_rev.click += new system.eventhandler(this.btn_oper); // // btn_dot // this.btn_dot.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_dot.location = new system.drawing.point(98, 144); this.btn_dot.name = "btn_dot"; this.btn_dot.size = new system.drawing.size(36, 29); this.btn_dot.tabindex = 38; this.btn_dot.tag = "0"; this.btn_dot.text = "."; this.btn_dot.click += new system.eventhandler(this.btn_oper); // // btn_add // this.btn_add.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_add.forecolor = system.drawing.color.red; this.btn_add.location = new system.drawing.point(138, 144); this.btn_add.name = "btn_add"; this.btn_add.size = new system.drawing.size(36, 29); this.btn_add.tabindex = 37; this.btn_add.text = "+"; this.btn_add.click += new system.eventhandler(this.btn_oper); // // btn_equ // this.btn_equ.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_equ.forecolor = system.drawing.color.red; this.btn_equ.location = new system.drawing.point(178, 144); this.btn_equ.name = "btn_equ"; this.btn_equ.size = new system.drawing.size(36, 29); this.btn_equ.tabindex = 36; this.btn_equ.text = "="; this.btn_equ.click += new system.eventhandler(this.btn_equ_click); // // btn_sign // this.btn_sign.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_sign.forecolor = system.drawing.color.blue; this.btn_sign.location = new system.drawing.point(58, 144); this.btn_sign.name = "btn_sign"; this.btn_sign.size = new system.drawing.size(36, 29); this.btn_sign.tabindex = 35; this.btn_sign.text = "+/-"; this.btn_sign.click += new system.eventhandler(this.btn_oper); // // btn_sub // this.btn_sub.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_sub.forecolor = system.drawing.color.red; this.btn_sub.location = new system.drawing.point(138, 112); this.btn_sub.name = "btn_sub"; this.btn_sub.size = new system.drawing.size(36, 29); this.btn_sub.tabindex = 34; this.btn_sub.text = "-"; this.btn_sub.click += new system.eventhandler(this.btn_oper); // // btn_mul // this.btn_mul.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_mul.forecolor = system.drawing.color.red; this.btn_mul.location = new system.drawing.point(138, 80); this.btn_mul.name = "btn_mul"; this.btn_mul.size = new system.drawing.size(36, 29); this.btn_mul.tabindex = 33; this.btn_mul.text = "*"; this.btn_mul.click += new system.eventhandler(this.btn_oper); // // btn_0 // this.btn_0.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_0.forecolor = system.drawing.color.blue; this.btn_0.location = new system.drawing.point(18, 144); this.btn_0.name = "btn_0"; this.btn_0.size = new system.drawing.size(36, 29); this.btn_0.tabindex = 32; this.btn_0.tag = "0"; this.btn_0.text = "0"; this.btn_0.click += new system.eventhandler(this.btn_0_click); // // btn_3 // this.btn_3.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_3.forecolor = system.drawing.color.blue; this.btn_3.location = new system.drawing.point(98, 112); this.btn_3.name = "btn_3"; this.btn_3.size = new system.drawing.size(36, 29); this.btn_3.tabindex = 31; this.btn_3.tag = "3"; this.btn_3.text = "3"; this.btn_3.click += new system.eventhandler(this.btn_0_click); // // btn_2 // this.btn_2.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_2.forecolor = system.drawing.color.blue; this.btn_2.location = new system.drawing.point(58, 112); this.btn_2.name = "btn_2"; this.btn_2.size = new system.drawing.size(36, 29); this.btn_2.tabindex = 30; this.btn_2.tag = "2"; this.btn_2.text = "2"; this.btn_2.click += new system.eventhandler(this.btn_0_click); // // btn_1 // this.btn_1.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_1.forecolor = system.drawing.color.blue; this.btn_1.location = new system.drawing.point(18, 112); this.btn_1.name = "btn_1"; this.btn_1.size = new system.drawing.size(36, 29); this.btn_1.tabindex = 29; this.btn_1.tag = "1"; this.btn_1.text = "1"; this.btn_1.click += new system.eventhandler(this.btn_0_click); // // btn_6 // this.btn_6.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_6.forecolor = system.drawing.color.blue; this.btn_6.location = new system.drawing.point(98, 80); this.btn_6.name = "btn_6"; this.btn_6.size = new system.drawing.size(36, 29); this.btn_6.tabindex = 28; this.btn_6.tag = "6"; this.btn_6.text = "6"; this.btn_6.click += new system.eventhandler(this.btn_0_click); // // btn_5 // this.btn_5.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_5.forecolor = system.drawing.color.blue; this.btn_5.location = new system.drawing.point(58, 80); this.btn_5.name = "btn_5"; this.btn_5.size = new system.drawing.size(36, 29); this.btn_5.tabindex = 27; this.btn_5.tag = "5"; this.btn_5.text = "5"; this.btn_5.click += new system.eventhandler(this.btn_0_click); // // btn_4 // this.btn_4.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_4.forecolor = system.drawing.color.blue; this.btn_4.location = new system.drawing.point(18, 80); this.btn_4.name = "btn_4"; this.btn_4.size = new system.drawing.size(36, 29); this.btn_4.tabindex = 26; this.btn_4.tag = "4"; this.btn_4.text = "4"; this.btn_4.click += new system.eventhandler(this.btn_0_click); // // btn_sqrt // this.btn_sqrt.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_sqrt.forecolor = system.drawing.color.blue; this.btn_sqrt.location = new system.drawing.point(18, 16); this.btn_sqrt.name = "btn_sqrt"; this.btn_sqrt.size = new system.drawing.size(76, 29); this.btn_sqrt.tabindex = 25; this.btn_sqrt.text = "sqrt"; this.btn_sqrt.click += new system.eventhandler(this.btn_oper); // // btn_div // this.btn_div.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_div.forecolor = system.drawing.color.red; this.btn_div.location = new system.drawing.point(138, 48); this.btn_div.name = "btn_div"; this.btn_div.size = new system.drawing.size(36, 29); this.btn_div.tabindex = 24; this.btn_div.text = "/"; this.btn_div.click += new system.eventhandler(this.btn_oper); // // btn_7 // this.btn_7.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_7.forecolor = system.drawing.color.blue; this.btn_7.location = new system.drawing.point(18, 48); this.btn_7.name = "btn_7"; this.btn_7.size = new system.drawing.size(36, 29); this.btn_7.tabindex = 23; this.btn_7.tag = "7"; this.btn_7.text = "7"; this.btn_7.click += new system.eventhandler(this.btn_0_click); // // btn_8 // this.btn_8.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_8.forecolor = system.drawing.color.blue; this.btn_8.location = new system.drawing.point(58, 48); this.btn_8.name = "btn_8"; this.btn_8.size = new system.drawing.size(36, 29); this.btn_8.tabindex = 22; this.btn_8.tag = "8"; this.btn_8.text = "8"; this.btn_8.click += new system.eventhandler(this.btn_0_click); // // btn_9 // this.btn_9.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_9.forecolor = system.drawing.color.blue; this.btn_9.location = new system.drawing.point(98, 48); this.btn_9.name = "btn_9"; this.btn_9.size = new system.drawing.size(36, 29); this.btn_9.tabindex = 21; this.btn_9.tag = "9"; this.btn_9.text = "9"; this.btn_9.click += new system.eventhandler(this.btn_0_click); // // btn_sqr // this.btn_sqr.font = new system.drawing.font("宋体", 10.5f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(134))); this.btn_sqr.forecolor = system.drawing.color.blue; this.btn_sqr.location = new system.drawing.point(98, 16); this.btn_sqr.name = "btn_sqr"; this.btn_sqr.size = new system.drawing.size(36, 29); this.btn_sqr.tabindex = 19; this.btn_sqr.text = "sqr"; this.btn_sqr.click += new system.eventhandler(this.btn_oper); // // mainmenu1 // this.mainmenu1.menuitems.addrange(new system.windows.forms.menuitem[] { this.menuitem8, this.menuitem1, this.menuitem4}); // // menuitem1 // this.menuitem1.index = 1; this.menuitem1.menuitems.addrange(new system.windows.forms.menuitem[] { this.menuitem2, this.menuitem3}); this.menuitem1.text = "编辑(&e)"; // // menuitem2 // this.menuitem2.index = 0; this.menuitem2.text = "复制(&c)"; this.menuitem2.click += new system.eventhandler(this.menuitem2_click); // // menuitem3 // this.menuitem3.index = 1; this.menuitem3.text = "粘贴(&p)"; this.menuitem3.click += new system.eventhandler(this.menuitem3_click); // // menuitem4 // this.menuitem4.index = 2; this.menuitem4.menuitems.addrange(new system.windows.forms.menuitem[] { this.menuitem5, this.menuitem6}); this.menuitem4.text = "帮助(&h)"; // // menuitem5 // this.menuitem5.index = 0; this.menuitem5.text = "帮助主题(&h)"; this.menuitem5.click += new system.eventhandler(this.menuitem5_click); // // menuitem6 // this.menuitem6.index = 1; this.menuitem6.text = "关于(&a)"; this.menuitem6.click += new system.eventhandler(this.menuitem6_click); // // menuitem8 // this.menuitem8.index = 0; this.menuitem8.menuitems.addrange(new system.windows.forms.menuitem[] { this.menuitem9, this.menuitem10}); this.menuitem8.text = "文件(&f)"; // // menuitem9 // this.menuitem9.index = 0; this.menuitem9.text = "打开windows计算器(&o)"; this.menuitem9.click += new system.eventhandler(this.menuitem9_click); // // menuitem10 // this.menuitem10.index = 1; this.menuitem10.text = "退出(&q)"; this.menuitem10.click += new system.eventhandler(this.menuitem10_click); // // form1 // this.autoscalebasesize = new system.drawing.size(6, 14); this.clientsize = new system.drawing.size(278, 239); this.controls.add(this.groupbox1); this.controls.add(this.txtshow); this.formborderstyle = system.windows.forms.formborderstyle.fixed3d; this.icon = ((system.drawing.icon)(resources.getobject("$this.icon"))); this.maximizebox = false; this.menu = this.mainmenu1; this.name = "form1"; this.startposition = system.windows.forms.formstartposition.centerscreen; this.text = "计算器"; this.groupbox1.resumelayout(false); this.resumelayout(false);
} #endregion
#region 各变量和常数的声明 public const int null = 0; // 定义操作码 public const int add = 1; //表示加 public const int sub = 2; //减 public const int mul = 3; //乘 public const int div = 4; //除 public const int sqr = 5; //求平方 public const int sqrt = 6; //求平方根 public const int nodot = 0; // 定义是否点击了小数点,0 为没点 public const int hasdot = 1; private double res = 0; // 记录结果数 private double tmp = 0; // 当前输入的操作数 private int opt = null; // 记录操作码 private int dot = nodot; // 记录是否点击了小数点,0为没有点 private int num = 0; // 记录输入操作数的个数 private int dotnum = 0; // 记录小数点部分的个数 string stroper; //获取操作符 #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [stathread] static void main() { application.run(new form1()); }