版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 脑损伤与输血相关性研究进展-洞察及研究
- 初中物理教学中实验教学与生活实际的联系课题报告教学研究课题报告
- 柴葛解肌汤效应机制研究-洞察及研究
- 基于体征分析的CPR干预效果预测研究-洞察及研究
- 传统文化在小学语文教学中的应用与探索教学研究课题报告
- 混合动力充电策略优化-洞察及研究
- 仓库火灾危险品泄漏事故应急安全演练方案
- 安全隐患排查工作报告范文
- 输液不良反应的护理
- 2025 年大学葡萄与葡萄酒工程(葡萄酒技术)试题及答案
- 2026年售后服务管理制度完善与企业售后工作规范化指南
- 2024-2025学年山东省烟台市招远市一年级(上)期末数学试卷
- 营销分析年终总结
- 2025年高考化学习题分类练:化学反应机理的探究
- “一带一路”人工智能应用场景案例集2025
- 医院成本管控模式的创新与案例分析
- 国网公司两票课件
- 2025-2026学年苏教版(新教材)小学科学三年级上册科学期末复习卷及答案
- 2025年全国高校辅导员素质能力大赛基础知识测试题(附答案)
- n2级护士理论考试试题附答案
- 2025版煤矿安全规程新增变化条款考试题库
评论
0/150
提交评论