基本信息
源码名称:C# 入门级计算器源码(实现了加减乘除等)
源码大小:0.11M
文件格式:.rar
开发语言:C#
更新时间:2016-02-02
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
之前做的一个小计算器,算法有点复杂QAQ
已知Bug:连续点击两次运算符号会导致结果出错。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _001Software_计算器 { public partial class Form1 : Form { bool Cal_Started, Res = false, Cltxt = true; int type, ltype; double first, second, result; public Form1() { InitializeComponent(); } private void button_cls_Click(object sender, EventArgs e) { Cls(); } public void Cls() { Cal_Started = false; Output.Text = ""; } public void Cal() { Cltxt = true; if (Cal_Started == false) { Cal_Started = true; ltype = type; //try ... catch first = double.Parse(Output.Text); } else if (Cal_Started == true) { //try ... catch second = double.Parse(Output.Text); if (Res == true) { switch (type) { case 1: result = first second; break; case 2: result = first - second; break; case 3: result = first * second; break; case 4: result = first / second; break; } } else { switch (ltype) { case 1: result = first second; break; case 2: result = first - second; break; case 3: result = first * second; break; case 4: result = first / second; break; } } first = result; Output.Text = result.ToString(); } } public void Input(string text) { if (Cltxt == false) { Output.Text = text; } else { Output.Text = text; Cltxt = false; } } private void Form1_Load(object sender, EventArgs e) { Cal_Started = false; } private void button_0_Click(object sender, EventArgs e) { Input(button_0.Text); } private void button_1_Click(object sender, EventArgs e) { Input(button_1.Text); } private void button_2_Click(object sender, EventArgs e) { Input(button_2.Text); } private void button_3_Click(object sender, EventArgs e) { Input(button_3.Text); } private void button_4_Click(object sender, EventArgs e) { Input(button_4.Text); } private void button_5_Click(object sender, EventArgs e) { Input(button_5.Text); } private void button_6_Click(object sender, EventArgs e) { Input(button_6.Text); } private void button_7_Click(object sender, EventArgs e) { Input(button_7.Text); } private void button_8_Click(object sender, EventArgs e) { Input(button_8.Text); } private void button_9_Click(object sender, EventArgs e) { Input(button_9.Text); } private void button_add_Click(object sender, EventArgs e) { type = 1; Cal(); } private void button_sub_Click(object sender, EventArgs e) { type = 2; Cal(); } private void button_mul_Click(object sender, EventArgs e) { type = 3; Cal(); } private void button_div_Click(object sender, EventArgs e) { type = 4; Cal(); } private void button_dot_Click(object sender, EventArgs e) { if (Cltxt == true) { Output.Text = "0."; Cltxt = false; } else { Output.Text = "."; } } private void button_res_Click(object sender, EventArgs e) { Res = true; Cal(); Cal_Started = false; } } }