首页 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 WindowsFormsApplication1 { public partial class Form1 : ...

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 WindowsFormsApplication1 { public partial class Form1 : Form { double num1, num2; string operation; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) //0~9以及小数点控件 { if (textBox1.Text.Length == 1 && textBox1.Text == "0" || textBox1.Text.Length == 1 && textBox1.Text == ".") textBox1.Text = (sender as Button).Text; else textBox1.Text += (sender as Button).Text; } private void button11_Click(object sender, EventArgs e) //=控件 { num2 = Convert.ToDouble(textBox1.Text); switch (operation) { case ("+"): textBox1.Text = Convert.ToString(num1 + num2); break; case ("-"): textBox1.Text = Convert.ToString(num1 - num2); break; case ("*"): textBox1.Text = Convert.ToString(num1 * num2); break; case ("/"): textBox1.Text = Convert.ToString(num1 / num2); break; } } private void button12_Click(object sender, EventArgs e)  //+ - * /控件 { operation = (sender as Button).Text; ; num1 = Convert.ToDouble(textBox1.Text); textBox1.Text = ""; } private void button16_Click(object sender, EventArgs e)  //清除 { num1 = 0; num2 = 0; textBox1.Text = ""; } } } 0~9以及小数点控件的事件都在每个控件的Click事件选择button1_Click 同理 + - * /控件 在此,我想说明一下: 1小数点是有很大缺陷的(会出现12.12.12这样的数)。 (望有识之士帮忙改正) 2像12+12+12=这样的运算不能实现。 3可能还有其他的明显不足(本人能力有限)。
本文档为【C#计算器代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_014457
暂无简介~
格式:doc
大小:19KB
软件:Word
页数:0
分类:互联网
上传时间:2019-08-31
浏览量:9