windows窗体计算器_第1页
windows窗体计算器_第2页
windows窗体计算器_第3页
windows窗体计算器_第4页
windows窗体计算器_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace test1 public partial class Form1 : Form public string a; public string a1; public string sign; public string sign_qe;/定义一个缺额标记 publi

2、c string sign_sum;/定义加号标记 public string sign_sub;/定义减号标记 public string sign_mul;/定义乘号标记 public string sign_div;/定义除号标记 public string sign_dian;/定义小数点标记 public string sign_bfhao;/定义一个百分号标记 public string sign_equ;/等于号标记 public string cpy;/导航菜单用于复制的内容数据 public double b = 10241024.10241023;/定义一个操作数b pub

3、lic double c = 10241024.10241023;/定义一个操作数据c public double g = 0;/定义一个操作数g public string d;/等于号记忆运算符 public double x;/求倒数 public double f;/百分号暂存记忆运算符 public double e;/缺额运算符 public double m;/内存记忆运算符 public double M;/内存记忆运算符 public double s = 0;/根号运算符 public bool wuxiao = true;/定义一个除数不能为零的数 public bool

4、 teshu = true;/定义一个特殊标记 public string zhantie=null; public bool clock=true;/锁定按键运算符 public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) this.Text = 计算器; private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)/复制 Clipboard.SetText(txt_show.Text, TextDa

5、taFormat.Text); private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)/粘贴 a1 = Clipboard.GetText(); zhantie = null; for (int i = 0; i a1.Length; i+) if (int)a1i 57) zhantie = zhantie; break; if (zhantie != zhantie) txt_show.Text = Clipboard.GetText(); this.a = this.txt_show.Text; private

6、 void 标准型ToolStripMenuItem_Click(object sender, EventArgs e) private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)/帮助 Help.ShowHelp(this, C:WINDOWShELPcalc.chm); private void btn_0_Click(object sender, EventArgs e)/数字0键 if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空

7、显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_0.Text;/给a赋上0 this.txt_show.Text += this.btn_0.Text;/将0显示在显示器上 this.teshu = true; else this.txt_show.Text = 不能同时输入多个0!; /防止输入多个0 else this.txt_show.Text = null;/清空显示器上显示的0 this.txt_show.Text = this.btn_0.Text; this.a += this.btn_0.Text;/给a

8、赋值为输入的0 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void btn_1_Click(object sender, EventArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_1.Text;/给a赋上1 this.txt_show.Text += this.btn_1.Text;/将1显示在显示

9、器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的1 this.txt_show.Text = this.btn_1.Text; this.a += this.btn_1.Text;/给a 赋值为输入的1 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void btn_2_Click(object sender, EventArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Te

10、xt = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_2.Text;/给a赋上2 this.txt_show.Text += this.btn_2.Text;/将2显示在显示器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的2 this.txt_show.Text = this.btn_2.Text; this.a += this.btn_2.Text;/给a 赋值为输入的2 if (sign != null) this.sig

11、n_qe = null;/对缺额标记的内容进行清空 private void btn_3_Click(object sender, EventArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_3.Text;/给a赋上3 this.txt_show.Text += this.btn_3.Text;/将3显示在显示器上 this.teshu = true; else this.tx

12、t_show.Text = null;/清空显示器上显示的3 this.txt_show.Text = this.btn_3.Text; this.a += this.btn_3.Text;/给a 赋值为输入的3 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void btn_4_Click(object sender, EventArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断

13、在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_4.Text;/给a赋上4 this.txt_show.Text += this.btn_4.Text;/将4显示在显示器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的4 this.txt_show.Text = this.btn_4.Text; this.a += this.btn_4.Text;/给a 赋值为输入的4 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private

14、void btn_5_Click(object sender, EventArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_5.Text;/给a赋上5 this.txt_show.Text += this.btn_5.Text;/将5显示在显示器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的5 thi

15、s.txt_show.Text = this.btn_5.Text; this.a += this.btn_5.Text;/给a 赋值为输入的5 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void btn_6_Click(object sender, EventArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this

16、.btn_6.Text;/给a赋上6 this.txt_show.Text += this.btn_6.Text;/将1显示在显示器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的6 this.txt_show.Text = this.btn_6.Text; this.a += this.btn_6.Text;/给a 赋值为输入的6 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void btn_7_Click(object sender, Ev

17、entArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_7.Text;/给a赋上7 this.txt_show.Text += this.btn_7.Text;/将7显示在显示器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的7 this.txt_show.Text = this.btn_7.Text;

18、 this.a += this.btn_7.Text;/给a 赋值为输入的7 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void btn_8_Click(object sender, EventArgs e) if (wuxiao = true) if (teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_8.Text;/给a赋上8 this.txt_show.T

19、ext += this.btn_8.Text;/将8显示在显示器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的8 this.txt_show.Text = this.btn_8.Text; this.a += this.btn_8.Text;/给a 赋值为输入的8 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void btn_9_Click(object sender, EventArgs e) if (wuxiao = true) if (

20、teshu = false) this.txt_show.Text = null;/清空显示器的内容 if (a != 0)/判断在一开始运算按下的第一个按钮是不是为零 this.a += this.btn_9.Text;/给a赋上8 this.txt_show.Text += this.btn_9.Text;/将8显示在显示器上 this.teshu = true; else this.txt_show.Text = null;/清空显示器上显示的8 this.txt_show.Text = this.btn_9.Text; this.a += this.btn_9.Text;/给a 赋值为

21、输入的8 if (sign != null) this.sign_qe = null;/对缺额标记的内容进行清空 private void backspace_Click(object sender, EventArgs e)/后退键 if (wuxiao = true) if (a = null) /this.txt_show.Text = 请输入数据!; else if (a.Length != 0) this.txt_show.Text = a.Remove(a.Length - 1, 1).ToString();/显示区域上的数据 a = a.Remove(a.Length - 1,

22、1);/计算器内部数据向后退一 else this.txt_show.Text = 0.; this.teshu = false;/做特有的加号标记 private void ce_Click(object sender, EventArgs e)/一次运算完成后点击该按钮便会清空数据,再次输入就开始新的运算 this.txt_show.Text = 0.; this.a = null;/记录数据清空 this.sign = null; this.sign_sum = null; this.sign_sub = null; this.sign_mul = null; this.sign_div

23、 = null; this.sign_equ = null; this.sign_bfhao = null; this.sign_dian = null; this.sign_qe = null; this.b = 10241024.10241023; this.c = 10241024.10241023; this.d = null; this.f = 0; this.x = 0; this.s = 0; this.clock = true; this.wuxiao = true; /对各个数据进行初始化 private void div_Click(object sender, Event

24、Args e)/除号 if (wuxiao = true) if (this.a = .) else this.sign = this.btn_div.Text;/做运算符的通用标记 if (c=10241024.10241023)/判断是否与其他运算有关联 this.sign_div = this.btn_div.Text;/对除法做除号标记 b = 0; c = 0; this.sign_qe = this.btn_div.Text;/做缺额标记 this.c += Convert.ToDouble(a);/a的值赋给c this.e = this.c; this.f = this.e;

25、a = null;/将a的值置为0 sign_dian = null; else if (sign_equ = = & a != null)/按下等于号 开始新的运算 this.sign_equ = null; this.sign_div = null; this.c = 0; this.e = 0; this.c += Convert.ToDouble(a);/将a的值赋给c this.a = null; this.sign_div = this.btn_div.Text;/标记 return; else if (sign_div = / & sign_qe != / & sign_equ

26、= =)/判断是否联除 this.b += Convert.ToDouble(a); if (b = 0)/判断除数是否为0 if (b = 0 & c = 0) this.txt_show.Text = 0; this.clock = false; return; else c = 0; this.txt_show.Text = null; this.txt_show.Text = 除数不能为0!; this.wuxiao = false; return; this.c /= this.b; b = 0; a = null; sign_dian = null; this.txt_show.T

27、ext = Convert.ToString(c);/显示器上显示结果 return; else this.b += Convert.ToDouble(a);/将a的值传递给b this.sign_div = this.btn_div.Text; if (sign_sum = +) this.c += this.b; sign_sum = null; else if (sign_sub = -) this.c -= this.b; sign_sub = null; else if (sign_mul = *) this.c *= this.b; sign_mul = null; a = null; b = 0; sign_dian = null; this.txt_show.Text = Convert.ToString(c); return; private void mul_Click(object sender, EventArgs e)/乘号 if (wuxiao = true) if (this.a = .) else

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论