您好,欢迎访问三七文档
//添加方法publicdoubleadd(doublea,doublec){returna+b;}其余的你可以自己写下就好了·都是一样的·只是符号不一样·3个文本框4个点击按钮分别代表+-*/如果点击的+的按钮你在+的点击事件里面调用这个方法就好了//添加按钮+的事件privatevoidbtnX_1_Click(objectsender,EventArgse){//textbox3是等于的值this.textbox3.text=add(double.parse(this.textbox1.text),double.parse(this.textbox2.text)).tostring();}其余的按这个方法写就好了!privatevoidbtnX_1_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=1;}else{ttx_show.Text+=1;}}privatevoidbtnX_2_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=2;}else{ttx_show.Text+=2;}}privatevoidbtnX_3_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=3;}else{ttx_show.Text+=3;}}privatevoidbtnX_4_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=4;}else{ttx_show.Text+=4;}}privatevoidbtnX_5_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=5;}else{ttx_show.Text+=5;}}privatevoidbtnX_6_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=6;}else{ttx_show.Text+=6;}}privatevoidbtnX_7_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=7;}else{ttx_show.Text+=7;}}privatevoidbtnX_8_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=8;}else{ttx_show.Text+=8;}}privatevoidbtnX_9_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=9;}else{ttx_show.Text+=9;}}privatevoidbtnX_0_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=0;}else{ttx_show.Text+=0;}}privatevoidbtnX_round_Click(objectsender,EventArgse){//小数点代码if(ttx_show.Text==0.00){ttx_show.Text=0.;}else{ttx_show.Text+=.;}}privatevoidbtnX_bracket_left_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=(;}else{ttx_show.Text+=(;}}privatevoidbtnX_bracket_right_Click(objectsender,EventArgse){if(ttx_show.Text==0.00){ttx_show.Text=);}else{ttx_show.Text+=);}}#region【退格】privatevoidbtnX_backspace_Click(objectsender,EventArgse){ttx_show.Text=ttx_show.Text.Substring(0,ttx_show.Text.Length-1);//退格}#endregion#region【等号】privatevoidbtnX_equal_Click(objectsender,EventArgse){equal_fangfa();}#endregion#region【除号】privatevoidbtnX_divided_Click(objectsender,EventArgse){if(ttx_show.Text!=0.00){ttx_show.Text+=/;}}#endregion#region【乘号】privatevoidbtnX_multiply_Click(objectsender,EventArgse){if(ttx_show.Text!=0.00){ttx_show.Text+=*;}}#endregion#region【减号】privatevoidbtnX_decrease_Click(objectsender,EventArgse){if(ttx_show.Text!=0.00){ttx_show.Text+=-;}}#endregion#region【加号】privatevoidbtnX_add_Click(objectsender,EventArgse){if(ttx_show.Text!=0.00){ttx_show.Text+=+;}}#endregion#region【清零】privatevoidbtnX_CE_Click(objectsender,EventArgse){i=0;ttx_show.Text=i.ToString(###,##0.00);}#endregion#endregion#region【自定义方法】privatevoidequal_fangfa(){try{equal=Evaluator.EvalToDouble(ttx_show.Text);//调用四则运算类}catch(Exceptionec){MessageBox.Show(错误代码为:+ec.Message);}ttx_show.Text=equal.ToString();}#endregion#region【键盘事件】privatevoidttx_show_KeyPress(objectsender,KeyPressEventArgse){if((int)e.KeyChar==(int)Keys.D1){if(ttx_show.Text==0.00){ttx_show.Text=1;}else{ttx_show.Text+=1;}}if((int)e.KeyChar==(int)Keys.D2){if(ttx_show.Text==0.00){ttx_show.Text=2;}else{ttx_show.Text+=2;}}if((int)e.KeyChar==(int)Keys.D3){if(ttx_show.Text==0.00){ttx_show.Text=3;}else{ttx_show.Text+=3;}}if((int)e.KeyChar==(int)Keys.D4){if(ttx_show.Text==0.00){ttx_show.Text=4;}else{ttx_show.Text+=4;}}if((int)e.KeyChar==(int)Keys.D5){if(ttx_show.Text==0.00){ttx_show.Text=5;}else{ttx_show.Text+=5;}}if((int)e.KeyChar==(int)Keys.D6){if(ttx_show.Text==0.00){ttx_show.Text=6;}else{ttx_show.Text+=6;}}if((int)e.KeyChar==(int)Keys.D7){if(ttx_show.Text==0.00){ttx_show.Text=7;}else{ttx_show.Text+=7;}}if((int)e.KeyChar==(int)Keys.D8){if(ttx_show.Text==0.00){ttx_show.Text=8;}else{ttx_show.Text+=8;}}if((int)e.KeyChar==(int)Keys.D9){if(ttx_show.Text==0.00){ttx_show.Text=9;}else{ttx_show.Text+=9;}}if((int)e.KeyChar==(int)Keys.D0){if(ttx_show.Text==0.00){ttx_show.Text=0;}else{ttx_show.Text+=0;}}#region【小键盘数字键】if((int)e.KeyChar==(int)Keys.NumPad1){if(ttx_show.Text==0.00){ttx_show.Text=1;}else{ttx_show.Text+=1;}}if((int)e.KeyChar==(int)Keys.NumPad2){if(ttx_show.Text==0.00){ttx_show.Text=2;}else{ttx_show.Text+=2;}}if((int)e.KeyChar==(int)Keys.NumPad3){if(ttx_show.Text==0.00){ttx_show.Text=3;}else{ttx_show.Text+=3;}}if((int)e.KeyChar==(int)Keys.NumPad4){if(ttx_show.Text==0.00){ttx_show.Text=4;}else{ttx_show.Text+=4;}}if((int)e.KeyChar==(int)Keys.NumPad5){if(ttx_show.Text==0.00){ttx_show.Text=5;}else{ttx_show.Text+=5;}}if((int)e.KeyChar==(int)Keys.NumPad6){if(ttx_show.Text==0.00){ttx_show.Text=6;}else{ttx_show.Text+=6;}}if((int)e.KeyChar==(int)Keys.NumPad7){if(ttx_show.Text==0.00){ttx_show.Text=7;}else{ttx_show.Text+=7;}}if((int)e.KeyChar==(int)Keys.NumPad8){if(ttx_show.Text==0.00){ttx_show.Text=8;}else{ttx_show.Text+=8;}}if((int)e.KeyChar==(int)Keys.NumPad9){if(ttx_show.Text==0.00){ttx_show.Text=9;}else{ttx_show.Text+=9;}}if((int)e.KeyChar==(int)Keys.NumPad0){if(ttx_show.Text==0.00){ttx_show.Text=0;}else{ttx_show.Text+=0;}}#endregion#region【加号】if((int)e.KeyChar==
本文标题:计算器编程代码
链接地址:https://www.777doc.com/doc-3152047 .html