版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、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; i
2、nt 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;
3、 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);
4、 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
5、; 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 += "=
6、" 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
7、= 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); th
8、is.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.numInp
9、ut.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.Tex
10、t += "/" 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.Text += num1.ToString(); numInput.Text = "" this.txtInput.Text += "+" op = 1; public double Mod(do
11、uble x, double y)/取模运算 max = 0; int temp = Convert.ToInt32(x / y); return (x - y * temp); private void power_Click(object sender, EventArgs e)/幂运算 max = 0; if (flag = 1 && sp = 0) num1 = Convert.ToDouble(numInput.Text); this.txtInput.Text += num1.ToString(); this.numInput.Text = ""
12、 this.txtInput.Text += "" op = 5; private void recip_Click(object sender, EventArgs e)/倒数 max = 0; if (flag = 1 && sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = 0; temp = 1 / num1; this.txtInput.Text = "1/" + num1.ToString() + "=" this.numIn
13、put.Text = temp.ToString(); private void percent_Click(object sender, EventArgs e) max = 0; if (flag = 1 && sp = 0) /double temp = Convert.ToDouble(this.numInput.Text); /this.txtInput.Text += temp.ToString(); /temp = temp / 100; /this.numInput.Text = temp.ToString(); /this.txtInput.Text += &
14、quot;%=" num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num1.ToString(); this.numInput.Text = "" this.txtInput.Text += "%" op = 6; #endregion #region 数字 private void one_Click(object sender, EventArgs e)/1 if (flag = 1 && sp = 0 && max = 0
15、) if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "1" eq = 0; else this.numInput.Text += "1" private void two_Click(object sender, EventArgs e)/2 if (flag = 1 && sp = 0 && max = 0) if (this.numInput.Text =
16、 "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "2" eq = 0; else this.numInput.Text += "2" /this.txtInput.Text += "2" private void three_Click(object sender, EventArgs e)/3 if (flag = 1 && sp = 0 && max = 0) if (this.nu
17、mInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "3" eq = 0; else this.numInput.Text += "3" /this.txtInput.Text += "3" private void four_Click(object sender, EventArgs e)/4 if (flag = 1 && sp = 0 && max = 0)
18、 if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "4" eq = 0; else this.numInput.Text += "4" / this.txtInput.Text += "4" private void five_Click(object sender, EventArgs e)/5 if (flag = 1 && sp = 0 &&
19、amp; max = 0) if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "5" eq = 0; else this.numInput.Text += "5" /this.txtInput.Text += "5" private void six_Click(object sender, EventArgs e)/6 if (flag = 1 && sp
20、 = 0 && max = 0) if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "6" eq = 0; else this.numInput.Text += "6" /this.txtInput.Text += "6" private void seven_Click(object sender, EventArgs e)/7 if (flag = 1
21、&& sp = 0 && max = 0) if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "7" eq = 0; else this.numInput.Text += "7" /this.txtInput.Text += "7" private void eight_Click(object sender, EventArgs e)/8
22、if (flag = 1 && sp = 0 && max = 0) if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "8" eq = 0; else this.numInput.Text += "8" /this.txtInput.Text += "8" private void night_Click(object sender, Ev
23、entArgs e)/9 if (flag = 1 && sp = 0 && max = 0) if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "9" eq = 0; else this.numInput.Text += "9" /this.txtInput.Text += "9" private void zero_Click(objec
24、t sender, EventArgs e)/0 if (flag = 1 && sp = 0 && max = 0) if (this.numInput.Text = "0") this.numInput.Text = "" if (eq = 1) this.numInput.Text = "0" eq = 0; else this.numInput.Text += "0" /this.txtInput.Text += "0" private void dian
25、_Click(object sender, EventArgs e)/小数点 if (flag = 1 && sp = 0 && max = 0) if (eq = 1) this.numInput.Text = "." eq = 0; else this.numInput.Text += "." /this.txtInput.Text += "." #endregion #region 三角函数 private void sin_Click(object sender, EventArgs e)/si
26、n if (flag = 1 && sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = Math.PI * (num1 / 180); this.txtInput.Text += "sin(" + num1 + ")=" num1 = Math.Sin(temp); this.numInput.Text = num1.ToString(); /this.txtInput.Text += num1.ToString(); private void cos_Cl
27、ick(object sender, EventArgs e)/cos if (flag = 1 && sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = Math.PI * (num1 / 180); this.txtInput.Text += "cos(" + num1 + ")=" num1 = Math.Cos(temp); this.numInput.Text = num1.ToString(); private void tan_Click(ob
28、ject sender, EventArgs e)/tan if (flag = 1 && sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = Math.PI * (num1 / 180); this.txtInput.Text += "tan(" + num1 + ")=" num1 = Math.Tan(temp); this.numInput.Text = num1.ToString(); #endregion #region 帮助 private v
29、oid 关于产品ToolStripMenuItem_Click(object sender, EventArgs e) MenuAbout about = new MenuAbout(); about.Show(); private void change_Click(object sender, EventArgs e) max = 0; if (flag = 1&&sp = 0) num1 = Convert.ToDouble(this.numInput.Text); num1 = -num1; this.numInput.Text = num1.ToString(); p
30、rivate void 使用手册ToolStripMenuItem_Click(object sender, EventArgs e) MenuUse use = new MenuUse(); use.Show(); #endregion #region 皮肤 private void 皮肤1ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.SkinFile = Application.StartupPath + "Calmness.ssk" private void 皮肤2ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.SkinFile = Application.StartupPath + "DeepCyan.ssk" private void 皮肤3ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.SkinFile =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2023三年级语文下册 第七单元 语文园地配套教案 新人教版
- 自招保安合同(2篇)
- 唐诗《墨梅》课件
- 经营杠杆 课件
- 西京学院《数字逻辑与数字电路》2022-2023学年期末试卷
- 幼儿园小班音乐 《大鱼和小鱼》课件
- 西京学院《建设法规》2022-2023学年第一学期期末试卷
- HF均相离子交换膜
- 西京学院《广告摄影与摄像》2023-2024学年第一学期期末试卷
- 西京学院《房地产开发经营与管理》2022-2023学年第一学期期末试卷
- 集装箱购销协议合同范本示例
- 求职面试技巧培训
- 室内装修施工安全方案
- 工程询价合同模板
- 事业单位招聘《综合基础知识》考试试题及答案
- 无锡风机吊装施工方案
- 《突发事件应急预案管理办法》知识培训
- 江苏省南京市建邺区2024-2025学年九年级上学期期中考试物理试题(无答案)
- 中小学师德师风建设各项制度汇编
- 第九章 职业健康安全与环境管理课件
- 2024年保安员证考试题库及答案(共260题)
评论
0/150
提交评论