首页 C#控制台计算器代码

C#控制台计算器代码

举报
开通vip

C#控制台计算器代码C#控制台计算器代码 using System; using System.Collections.Generic;using System.ComponentModel;using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace Caculator { public partial class Form1 : Form { public st...

C#控制台计算器代码
C#控制台计算器代码 using System; using System.Collections.Generic;using System.ComponentModel;using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace Caculator { public partial class Form1 : Form { public string ok1; public int OperationType; public double okl1, okl2; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) //退格 { if (textBox1.Text == "" || textBox1.Text == "0") { textBox1.Text = ""; } else { okl1 = Convert.ToDouble(textBox1.Text); ok1 = Convert.ToString((okl1 - okl1 % 10) / 10); textBox1.Text = ok1; } } private void button2_Click(object sender, EventArgs e) //清空按钮 { ok1 = ""; textBox1.Text = "0"; textBox1.Focus(); } private void button9_Click(object sender, EventArgs e) //1按钮 { if (textBox1.Text == "0") { ok1 = "1"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "1"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button10_Click(object sender, EventArgs e) //2 { if (textBox1.Text == "0") { ok1 = "2"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "2"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button11_Click(object sender, EventArgs e) //3 { if (textBox1.Text == "0") { ok1 = "3"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "3"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button6_Click(object sender, EventArgs e) //4 { if (textBox1.Text == "0") { ok1 = "4"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "4"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button5_Click(object sender, EventArgs e) //5 { if (textBox1.Text == "0") { ok1 = "5"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "5"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button8_Click(object sender, EventArgs e) //6 { if (textBox1.Text == "0") { ok1 = "6"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "6"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button3_Click(object sender, EventArgs e) //7 { if (textBox1.Text == "0") { ok1 = "7"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "7"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button4_Click(object sender, EventArgs e) //8 { if (textBox1.Text == "0") { ok1 = "8"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "8"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button7_Click(object sender, EventArgs e) //9 { if (textBox1.Text == "0") { ok1 = "9"; textBox1.Text = Convert.ToString(ok1); } else { ok1 = ok1 + "9"; okl2 = Convert.ToDouble(ok1); textBox1.Text = ok1; } } private void button15_Click(object sender, EventArgs e) //0 { ok1 = ok1 + "0"; okl2 = Convert.ToDouble(ok1); this.textBox1.Text=ok1; } private void button17_Click(object sender, EventArgs e) //. { try { ok1 = Convert.ToString(ok1 + "."); textBox1.Text = Convert.ToString(ok1 + ""); } catch { } } private void button16_Click(object sender, EventArgs e) // +/- 正钮 { okl1 = Convert.ToDouble(textBox1.Text); textBox1.Text = Convert.ToString(0 - okl1); } private void button18_Click(object sender, EventArgs e) // - { if (textBox1.TextLength > 0) { okl1 = Convert.ToDouble(textBox1.Text); ok1 = ""; OperationType = 2; textBox1.Text = ""; textBox1.Focus(); } } private void button14_Click(object sender, EventArgs e) // + { if (textBox1.TextLength > 0) { okl1 = Convert.ToDouble(textBox1.Text); ok1 = ""; OperationType = 1; textBox1.Text = ""; textBox1.Focus(); } } private void button13_Click(object sender, EventArgs e) //* { if (textBox1.TextLength > 0) { okl1 = Convert.ToDouble(textBox1.Text); ok1 = ""; OperationType = 3; textBox1.Text = ""; textBox1.Focus(); } } private void button12_Click(object sender, EventArgs e) // / { if (textBox1.TextLength > 0) { okl1 = Convert.ToDouble(textBox1.Text); ok1 = ""; OperationType = 4; textBox1.Text = ""; textBox1.Focus(); } } private void button22_Click(object sender, EventArgs e) //= { switch (OperationType) { case 1: textBox1.Text = Convert.ToString(okl1 + Convert.ToDouble(ok1)); okl2 = Convert.ToDouble(textBox1.Text); break; case 2: textBox1.Text = Convert.ToString(okl1 - Convert.ToDouble(ok1)); okl2 = Convert.ToDouble(textBox1.Text); break; case 3: textBox1.Text = Convert.ToString(okl1 * Convert.ToDouble(ok1)); okl2 = Convert.ToDouble(textBox1.Text); break; case 4: textBox1.Text = Convert.ToString(okl1 / Convert.ToDouble(ok1)); okl2 = Convert.ToDouble(textBox1.Text); break; } ok1 = ""; okl1 = Convert.ToDouble(textBox1.Text); } private void button21_Click(object sender, EventArgs e) // /% 倒数 { if (Convert.ToDouble(textBox1.Text) == 0) { this.textBox1.Text = "error"; } else { okl2 = Convert.ToDouble(textBox1.Text); ok1 = ""; textBox1.Text = Convert.ToString(1 / okl2); } } private void button20_Click(object sender, EventArgs e) //% { ok1 = Convert.ToString(Convert.ToDouble(textBox1.Text) / 100); textBox1.Text = ok1; ok1 = ""; } private void button19_Click(object sender, EventArgs e) //sqrt求平方根 { if (Convert.ToDouble(textBox1.Text) < 0) { this.textBox1.Text = "error"; } else { okl2 = Convert.ToDouble(textBox1.Text); ok1 = ""; textBox1.Text = Convert.ToString(System.Math.Sqrt(okl2)); textBox1.Focus(); } } private void button24_Click(object sender, EventArgs e) { Application.Exit(); } private void button23_Click(object sender, EventArgs e) { Help.ShowHelp(this, "C:\\WINDOWS\\system32\\calc.exe"); } } }
本文档为【C#控制台计算器代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_882336
暂无简介~
格式:doc
大小:29KB
软件:Word
页数:0
分类:互联网
上传时间:2018-08-08
浏览量:7