收藏 分享(赏)

计算器编程代码.doc

上传人:gnk289057 文档编号:9499386 上传时间:2019-08-10 格式:DOC 页数:17 大小:180KB
下载 相关 举报
计算器编程代码.doc_第1页
第1页 / 共17页
计算器编程代码.doc_第2页
第2页 / 共17页
计算器编程代码.doc_第3页
第3页 / 共17页
计算器编程代码.doc_第4页
第4页 / 共17页
计算器编程代码.doc_第5页
第5页 / 共17页
点击查看更多>>
资源描述

1、/添加方法public double add(double a,double c)return a+b;其余的你可以自己 写下就好了都是一样的 只是符号不一样 3个文本框 4个点击按钮 分别代表 + - * / 如果点击的+的按钮你在+的点击事件里面 调用这个方法就好了/添加按钮+的事件private void btnX_1_Click(object sender, EventArgs e)/textbox3 是等于的值 this.textbox3.text=add(double.parse(this.textbox1.text),double.parse(this.textbox2.text

2、).tostring();其余的按这个方法写就好了!private void btnX_1_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “1“;elsettx_show.Text += “1“;private void btnX_2_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “2“;elsettx_show.Text += “2“;private void btnX_3_Clic

3、k(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “3“;elsettx_show.Text += “3“;private void btnX_4_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “4“;elsettx_show.Text += “4“;private void btnX_5_Click(object sender, EventArgs e)if (ttx_show.Text = “

4、0.00“)ttx_show.Text = “5“;elsettx_show.Text += “5“;private void btnX_6_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “6“;elsettx_show.Text += “6“;private void btnX_7_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “7“;elsettx_show.Text += “7“

5、;private void btnX_8_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “8“;elsettx_show.Text += “8“;private void btnX_9_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “9“;elsettx_show.Text += “9“;private void btnX_0_Click(object sender, EventArg

6、s e)if (ttx_show.Text = “0.00“)ttx_show.Text = “0“;elsettx_show.Text += “0“;private void btnX_round_Click(object sender, EventArgs e)/小数点代码if (ttx_show.Text = “0.00“)ttx_show.Text = “0.“;elsettx_show.Text += “.“;private void btnX_bracket_left_Click(object sender, EventArgs e)if (ttx_show.Text = “0.0

7、0“)ttx_show.Text = “(“;elsettx_show.Text += “(“;private void btnX_bracket_right_Click(object sender, EventArgs e)if (ttx_show.Text = “0.00“)ttx_show.Text = “)“;elsettx_show.Text += “)“;#region 【退格】private void btnX_backspace_Click(object sender, EventArgs e)ttx_show.Text = ttx_show.Text.Substring(0,

8、 ttx_show.Text.Length - 1);/退格#endregion#region 【等号】private void btnX_equal_Click(object sender, EventArgs e)equal_fangfa();#endregion#region 【除号】private void btnX_divided_Click(object sender, EventArgs e)if (ttx_show.Text != “0.00“)ttx_show.Text += “/“;#endregion#region 【乘号】private void btnX_multip

9、ly_Click(object sender, EventArgs e)if (ttx_show.Text != “0.00“)ttx_show.Text += “*“;#endregion#region 【减号】private void btnX_decrease_Click(object sender, EventArgs e)if (ttx_show.Text != “0.00“)ttx_show.Text += “-“;#endregion#region 【加号】private void btnX_add_Click(object sender, EventArgs e)if (ttx

10、_show.Text != “0.00“)ttx_show.Text += “+“;#endregion#region 【清零】private void btnX_CE_Click(object sender, EventArgs e)i = 0;ttx_show.Text = i.ToString(“#,#0.00“);#endregion#endregion#region 【自定义方法】private void equal_fangfa()tryequal = Evaluator.EvalToDouble(ttx_show.Text);/调用四则运算类catch (Exception ec

11、)MessageBox.Show(“错误代码为:“ + ec.Message);ttx_show.Text = equal.ToString();#endregion#region 【键盘事件】private void ttx_show_KeyPress(object sender, KeyPressEventArgs e)if (int)e.KeyChar = (int)Keys.D1)if (ttx_show.Text = “0.00“)ttx_show.Text = “1“;elsettx_show.Text += “1“;if (int)e.KeyChar = (int)Keys.D2

12、)if (ttx_show.Text = “0.00“)ttx_show.Text = “2“;elsettx_show.Text += “2“;if (int)e.KeyChar = (int)Keys.D3)if (ttx_show.Text = “0.00“)ttx_show.Text = “3“;elsettx_show.Text += “3“;if (int)e.KeyChar = (int)Keys.D4)if (ttx_show.Text = “0.00“)ttx_show.Text = “4“;elsettx_show.Text += “4“;if (int)e.KeyChar

13、 = (int)Keys.D5)if (ttx_show.Text = “0.00“)ttx_show.Text = “5“;elsettx_show.Text += “5“;if (int)e.KeyChar = (int)Keys.D6)if (ttx_show.Text = “0.00“)ttx_show.Text = “6“;elsettx_show.Text += “6“;if (int)e.KeyChar = (int)Keys.D7)if (ttx_show.Text = “0.00“)ttx_show.Text = “7“;elsettx_show.Text += “7“;if

14、 (int)e.KeyChar = (int)Keys.D8)if (ttx_show.Text = “0.00“)ttx_show.Text = “8“;elsettx_show.Text += “8“;if (int)e.KeyChar = (int)Keys.D9)if (ttx_show.Text = “0.00“)ttx_show.Text = “9“;elsettx_show.Text += “9“;if (int)e.KeyChar = (int)Keys.D0)if (ttx_show.Text = “0.00“)ttx_show.Text = “0“;elsettx_show

15、.Text += “0“;#region 【小键盘数字键】if (int)e.KeyChar = (int)Keys.NumPad1)if (ttx_show.Text = “0.00“)ttx_show.Text = “1“;elsettx_show.Text += “1“;if (int)e.KeyChar = (int)Keys.NumPad2)if (ttx_show.Text = “0.00“)ttx_show.Text = “2“;elsettx_show.Text += “2“;if (int)e.KeyChar = (int)Keys.NumPad3)if (ttx_show.

16、Text = “0.00“)ttx_show.Text = “3“;elsettx_show.Text += “3“;if (int)e.KeyChar = (int)Keys.NumPad4)if (ttx_show.Text = “0.00“)ttx_show.Text = “4“;elsettx_show.Text += “4“;if (int)e.KeyChar = (int)Keys.NumPad5)if (ttx_show.Text = “0.00“)ttx_show.Text = “5“;elsettx_show.Text += “5“;if (int)e.KeyChar = (

17、int)Keys.NumPad6)if (ttx_show.Text = “0.00“)ttx_show.Text = “6“;elsettx_show.Text += “6“;if (int)e.KeyChar = (int)Keys.NumPad7)if (ttx_show.Text = “0.00“)ttx_show.Text = “7“;elsettx_show.Text += “7“;if (int)e.KeyChar = (int)Keys.NumPad8)if (ttx_show.Text = “0.00“)ttx_show.Text = “8“;elsettx_show.Tex

18、t += “8“;if (int)e.KeyChar = (int)Keys.NumPad9)if (ttx_show.Text = “0.00“)ttx_show.Text = “9“;elsettx_show.Text += “9“;if (int)e.KeyChar = (int)Keys.NumPad0)if (ttx_show.Text = “0.00“)ttx_show.Text = “0“;elsettx_show.Text += “0“;#endregion#region 【加号】if (int)e.KeyChar = (int)Keys.Add)if (ttx_show.Te

19、xt != “0.00“)ttx_show.Text += “+“;#endregion#region 【减号】if (int)e.KeyChar = (int)Keys.Subtract)if (ttx_show.Text != “0.00“)ttx_show.Text += “-“;#endregion#region 【乘号】if (int)e.KeyChar = (int)Keys.Multiply)if (ttx_show.Text != “0.00“)ttx_show.Text += “*“;#endregion#region 【除号】if (int)e.KeyChar = (int

20、)Keys.Divide)if (ttx_show.Text != “0.00“)ttx_show.Text += “/“;#endregion#region 【小数点】if (int)e.KeyChar = (int)Keys.Decimal)/这里有问题,按小数点没反映/小数点代码if (ttx_show.Text = “0.00“)ttx_show.Text = “0.“;elsettx_show.Text += “.“;#endregion#region 【求结果-回车】if (int)e.KeyChar = (int)Keys.Enter)equal_fangfa();#endreg

21、ion#region 【退格键】if (int)e.KeyChar = (int)Keys.Back)ttx_show.Text = ttx_show.Text.Substring(0, ttx_show.Text.Length - 1);/退格#endregion#region 【清零】if (int)e.KeyChar = (int)Keys.Escape)i = 0;ttx_show.Text = i.ToString(“#,#0.00“);#endregion#endregion#region 【菜单-复制】private void 复制 CToolStripMenuItem_Clic

22、k(object sender, EventArgs e)if (ttx_show.SelectedText != “)Clipboard.SetDataObject(ttx_show.SelectedText);#endregion#region 【菜单-粘贴】private void 粘贴 VToolStripMenuItem_Click(object sender, EventArgs e)/莫看懂,拿来用IDataObject iData = Clipboard.GetDataObject();/ Determines whether the data is in a format y

23、ou can use.if (iData.GetDataPresent(DataFormats.Text)/ Yes it is, so display it in a text box.ttx_show.Text = (String)iData.GetData(DataFormats.Text);#endregion 下面是四则混合计算类class Evaluatorpublic static int EvalToInteger(string statement)string s = EvalToString(statement);return int.Parse(s.ToString();

24、public static double EvalToDouble(string statement)string s = EvalToString(statement);return double.Parse(s);public static string EvalToString(string statement)object o = EvalToObject(statement);return o.ToString();public static object EvalToObject(string statement)return _evaluatorType.InvokeMember

25、(“Eval“,BindingFlags.InvokeMethod,null,_evaluator,new object statement );static Evaluator()ICodeCompiler compiler;compiler = new JScriptCodeProvider().CreateCompiler();CompilerParameters parameters;parameters = new CompilerParameters();parameters.GenerateInMemory = true;CompilerResults results;resul

26、ts = compiler.CompileAssemblyFromSource(parameters, _jscriptSource);Assembly assembly = results.CompiledAssembly;_evaluatorType = assembly.GetType(“Evaluator.Evaluator“);_evaluator = Activator.CreateInstance(_evaluatorType);private static object _evaluator = null;private static Type _evaluatorType = null;private static readonly string _jscriptSource =“package Evaluator class Evaluator public function Eval(expr : String) : String return eval(expr); “;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报