开发工具:
文件大小: 13kb
下载次数: 0
上传时间: 2012-07-17
详细说明: 简单的四则运算 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 简单计算机 { public partial class Form1 : Form { string st = ""; double a=0, b=0; int i = 1; int flag,flag2;//初次执行算法的代号与再次执行算法的代号 bool format = false;//flag=true无需按清除,在执行下一次算法时候自动初始化 public Form1() { InitializeComponent(); textBox1.Text = Convert.ToString(0);//初始化,无操作时候,屏幕显示“0” } private void button1_Click(object sender, EventArgs e)//数字“1” { if (flag!=0)//以“=”的结果执行下一次加减乘除的初始化 { format = false; i = 1; } if (format == true)//执行下一次算法的初始化 { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button1.Text; textBox1.Text = st; } private void button2_Click(object sender, EventArgs e)//数字“2” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button2.Text; textBox1.Text = st; } private void button3_Click(object sender, EventArgs e)//数字“3” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button3.Text; textBox1.Text = st; } private void button4_Click(object sender, EventArgs e)//数字“4” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button4.Text; textBox1.Text = st; } private void button5_Click(object sender, EventArgs e)//数字“5” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button5.Text; textBox1.Text = st; } private void button6_Click(object sender, EventArgs e)//数字“6” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button6.Text; textBox1.Text = st; } private void button7_Click(object sender, EventArgs e)//数字“7” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button7.Text; textBox1.Text = st; } private void button8_Click(object sender, EventArgs e)//数字“8” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button8.Text; textBox1.Text = st; } private void button9_Click(object sender, EventArgs e)//数字“9” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button9.Text; textBox1.Text = st; } private void button10_Click(object sender, EventArgs e)//数字“0” { if (flag != 0) { format = false; i = 1; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; i = 1; } if (a != 0) textBox1.Text = ""; st = st + button10.Text; textBox1.Text = st; } private void button18_Click(object sender, EventArgs e)//数字“.” { if (flag != 0) { format = false; } if (format == true) { a = b = 0; flag = flag2 = 0; format = false; } if (a != 0) textBox1.Text = ""; if (st == "")//第一个数字是小数时候无需按“0”,直接显示“0” st = Convert.ToString(0); if (i == 1) { st = st + button18.Text; i++; } textBox1.Text = st; } private void button11_Click(object sender, EventArgs e)//初始化 { st = ""; a = b = 0; i = 1; flag = flag2 = 0; format = false; textBox1.Text = Convert.ToString(0); } private void button13_Click(object sender, EventArgs e)//相加 { flag = 1; if (a == 0) { if (st == "") st = "0"; a = Convert.ToDouble(st); } else if (st != "" && a != 0) b = Convert.ToDouble(st); if (Convert.ToString(b)!="") { textBox1.Text = ""; if (flag2 == 5) { a = a + b; } if (flag2 == 6) { a = a - b; } if (flag2 == 7) { a = a * b; } if (flag2 == 8) { if (b == 0) MessageBox.Show("被除数不能为0", "警告", MessageBoxButtons.RetryCancel); else { a = a / b; } } textBox1.Text = Convert.ToString(a); b = 0; st = ""; } flag2 = 5; } private void button14_Click(object sender, EventArgs e)//相减 { flag = 2; if (a == 0) { if (st == "") st = "0"; a = Convert.ToDouble(st); } else if (st != "" && a != 0) b = Convert.ToDouble(st); if (Convert.ToString(b) != "") { textBox1.Text = ""; if (flag2 == 5) { a = a + b; } if (flag2 == 6) { a = a - b; } if (flag2 == 7) { a = a * b; } if (flag2 == 8) { if (b == 0) MessageBox.Show("被除数不能为0", "警告", MessageBoxButtons.RetryCancel); else { a = a / b; } } textBox1.Text = Convert.ToString(a); b = 0; st = ""; } flag2 = 6; } private void button15_Click(object sender, EventArgs e)//相乘 { flag = 3; if (a == 0) { if (st == "") st = "0"; a = Convert.ToDouble(st); } else if (st != "" && a != 0) b = Convert.ToDouble(st); if (Convert.ToString(b) != "") { textBox1.Text = ""; if (flag2 == 5) { a = a + b; } if (flag2 == 6) { a = a - b; } if (flag2 == 7) { a = a * b; } if (flag2 == 8) { if (b == 0) MessageBox.Show("被除数不能为0", "警告", MessageBoxButtons.RetryCancel); else { a = a / b; } } textBox1.Text = Convert.ToString(a); b = 0; st = ""; } flag2 = 7; } private void button16_Click(object sender, EventArgs e)//相除 { flag = 4; if (a == 0) { if (st == "") st = "0"; a = Convert.ToDouble(st); } else if (st != "" && a != 0) b = Convert.ToDouble(st); if (Convert.ToString(b) != "") { textBox1.Text = ""; if (flag2 == 5) { a = a + b; } if (flag2 == 6) { a = a - b; } if (flag2 == 7) { a = a * b; } if (flag2 == 8) { if (b == 0) MessageBox.Show("被除数不能为0", "警告", MessageBoxButtons.RetryCancel); else { a = a / b; } } textBox1.Text = Convert.ToString(a); b = 0; st = ""; } flag2 = 8; } private void button17_Click(object sender, EventArgs e)//等于 { format = true; textBox1.Text = ""; if(st!="") b = Convert.ToDouble(st); if (flag == 1) { a = a + b; } if (flag == 2) { a =a - b; } if (flag == 3) { a = a * b; } if (flag == 4) { if (b == 0) MessageBox.Show("被除数不能为0","警告",MessageBoxButtons.RetryCancel); else { a = a / b; } } textBox1.Text = Convert.ToString(a); b = 0; flag = flag2 = 0; st = ""; } private void button12_Click(object sender, EventArgs e) { Application.Exit(); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.