轻量级前端框架助力开发者提升项目效率与性能
771
2022-11-07
制作计算器的代码(C#)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Text.RegularExpressions;
namespace caculator{publicpartialclasscaculator1Form {String//定义两个操作数bool//标识小数点是否存在int//记录操作数个数String//指示上一次按键事件的类型int//指示将要进行的操作类型bool//指示是否已经进行过操作String TempReadout;
public caculator1() {//初始化界面控件 }
privatevoidobjectEventArgs//小数点(.) {iftrue) {"0."; }true; }
publicvoidString//规范化显示 {if".") == -1) {"."; }else { ReadOut.Text=s; } }
privatevoidobjectEventArgs e) { calculate(1); }
privatevoidobjectEventArgs e) { calculate(2); }
privatevoidobjectEventArgs e) { calculate(3); }
privatevoidobjectEventArgs e) { calculate(4); }
privatevoidobjectEventArgs e) { calculate(5); }
privatevoidobjectEventArgs e) { calculate(6); }
privatevoidobjectEventArgs e) { calculate(7); }
privatevoidobjectEventArgs e) { calculate(8); }
privatevoidobjectEventArgs e) { calculate(9); }
publicvoidint//接收操作符 {if(!OperaterFlag) //判断以前是否单击过操作符,避免连击操作符错误 { NumOps = NumOps + 1; } switch (NumOps) {case 0:true;break;case 1: op1 = ReadOut.Text;true;break;case 2: op2 = ReadOut.Text;switch (OpFlag) {case 1:Double.Parse(op1) + Double.Parse(op2)).ToString(); //加break;case 3:Double.Parse(op1) - Double.Parse(op2)).ToString(); //减break;case 2:Double.Parse(op1) * Double.Parse(op2)).ToString();//乘break;case 0:ifDouble.Parse(op2) == 0) //除 {MessageBox.Show("除数不能为", "计算器"); }else {try {Double.Parse(op1) / Double.Parse(op2)).ToString(); }catchException e) {Console.WriteLine("Generic Exception Handler: {0}", e.ToString()); } }break;case 4://等 break; } TempReadout = op1;this.StandardizationShow(TempReadout); NumOps = 1;break; }if(NumOps!=0) { OpFlag = MyOperator; }true;false; // LastInput = "NUMS"; } privatevoidobjectEventArgs e) { OperatorCal(1); } privatevoidobjectEventArgs e) { OperatorCal(3); } privatevoidobjectEventArgs e) { OperatorCal(2); } privatevoidobjectEventArgs e) { OperatorCal(0); } privatevoidobjectEventArgs e) { OperatorCal(4); } privatevoidobjectEventArgs//% {Double.Parse(ReadOut.Text) / 100).ToString(); NumOps = NumOps + 1;true; } privatevoidobjectEventArgs//C {"0.";"";"";this, newEventArgs()); } privatevoidobjectEventArgs//CE {"0.";false;"CE"; } privatevoidobjectEventArgs//求倒数(/x) {Double.Parse(ReadOut.Text)).ToString(); } privatevoidobjectEventArgs//复制 {if(ReadOut.Text.Equals("")) {return; }Clipboard.SetDataObject(ReadOut.Text,true); } privatevoidobjectEventArgs//粘贴 {ifClipboard.GetDataObject().GetDataPresent(DataFormats.Text)) {this.paste.Enabled = true;"";this.ReadOut.Paste(); }else {this.paste.Enabled = false; } } privatevoidobjectEventArgs//删除(BackSpace) {if"0.") {try {"."; }catchException ex) {Console.WriteLine("Generic Exception Handler: {0}", ex.ToString()); } if(ReadOut.Text==".") {"0."; } } }
privatevoidobjectEventArgs e) {this.ReadOut.Text;this.ReadOut.Text = System.Convert.ToString(Math.Sqrt(System.Convert.ToDouble(TempReadout))); } } }
龙腾一族至尊龙骑
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~