资源预览内容
第1页 / 共13页
第2页 / 共13页
第3页 / 共13页
第4页 / 共13页
第5页 / 共13页
第6页 / 共13页
第7页 / 共13页
第8页 / 共13页
第9页 / 共13页
第10页 / 共13页
亲,该文档总共13页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Calculator public partial class Counter : Form public Counter() InitializeComponent(); double num1, num2; double result=0; int op; int flag=0;/开始标志 int sp = 0;/判断除数为零时移除监听 int max = 0;/范围标识 int eq=0; #region 功能键 private void on_Click(object sender, EventArgs e)/开始 flag = 1; sp = 0; max = 0; this.numInput.Text = 0; this.txtInput.Text = ; private void off_Click(object sender, EventArgs e)/关闭 flag = 0; sp = 0; max = 0; this.numInput.Text = ; this.txtInput.Text = ; private void button9_Click(object sender, EventArgs e)/删除 max = 0; if (flag = 1&sp=0) string numstring = this.numInput.Text; if (numstring.Length 0) string temp = numstring.Substring(0, numstring.Length - 1); this.numInput.Text = temp.ToString(); else this.numInput.Text = 0; private void clear_Click(object sender, EventArgs e)/c清零 max = 0; if (flag = 1) sp = 0; this.numInput.Text = 0; this.txtInput.Text = ; private void delete_Click(object sender, EventArgs e)/清零 max = 0; if (flag = 1) sp = 0; this.numInput.Text = 0; #endregion #region 运算符 private void equal_Click(object sender, EventArgs e)/等号 eq = 1; if (flag = 1 & sp = 0) max = 0; num2 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num2.ToString(); this.txtInput.Text += =; txtInput.Text = null; switch (op) case 1: result = num1 + num2; break; case 2: result = num1 - num2; break; case 3: result = num1 * num2; break; case 4: result = num1 / num2; break; case 5: result = Math.Pow(num1, num2); break; case 6: result = Mod(num1, num2); break; default: return; if (op = 4&num2 = 0) this.numInput.Text = 除数不能为0; sp = 1; else /this.txtInput.Text += result.ToString(); this.numInput.Text = result.ToString(); private void sub_Click(object sender, EventArgs e)/减法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num1.ToString(); numInput.Text = ; this.txtInput.Text += -; op = 2; private void mul_Click(object sender, EventArgs e)/乘法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num1.ToString(); this.numInput.Text = ; this.txtInput.Text += *; op = 3; private void divide_Click(object sender, EventArgs e)/除法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num1.ToString(); this.numInput.Text = ; this.txtInput.Text += /; op = 4; private void plus_Click(object sender, EventArgs e)/加法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Tex
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号