已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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.Text += num1.ToString(); numInput.Text = ; this.txtInput.Text += +; op = 1; public double Mod(double 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 = ; 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.numInput.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 += %=; 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) 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 = 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.numInput.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) 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 & 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 = 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 & 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 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, EventArgs 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(object 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_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)/sin 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_Click(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(object 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 void 关于产品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(); private 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 = Application.StartupPath + Eighteen.ssk; private void 皮肤4ToolStripMenuItem_Click(object s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025贷款合同样本模板
- 2025土地使用权承包合同书样本 农业用地承包合同书
- 注塑产品新人培训
- 职业暴露防护与培训
- 物业客户诉求培训
- 溃疡性结肠炎治疗要点培训
- 项目副经理核心能力培训
- 全科医学科高血压患者康复护理记录
- 儿科疟疾预防措施培训
- 沂蒙精神心得体会
- 基于碳基纳米材料的铅蓄电池电极性能优化与调控-洞察及研究
- 2025新疆交通投资(集团)有限责任公司所属公司招聘26人笔试历年典型考点题库附带答案详解2套试卷
- 2025年“才聚齐鲁成就未来”山东钢铁集团有限公司社会招聘13人笔试历年参考题库附带答案详解
- 2025年新三类人员安全员c证继续教育考试题库及答案
- 2025浙江台州市信保基金融资担保有限责任公司招聘10人笔试历年参考题库附带答案详解
- 企业危机管理中的社会责任与可持续发展研究-洞察及研究
- 幼儿园童话故事表演《丑小鸭》课件
- 2025年风力发电机叶片维护与性能提升可行性分析报告
- 村干部考入事业编面试真题(含答案)
- 西南交通大学2025年秋季管理岗位与其他专技岗位公开招聘考试参考试题及答案解析
- 2025年陕西省招聘村居后备干部考试应知应会题库及答案
评论
0/150
提交评论