⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 c#程序设计 实现其基本功能 可能有些bug请见谅
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 计算器
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{   protected double Number;
        protected char Caozuofu;
		protected bool Ksjieshou;
		protected bool Point;
        protected bool funot;
		private System.Windows.Forms.Label lblMem;
		private System.Windows.Forms.MainMenu mainMenu1;
        protected double iMem;
		protected void ResetState()
		{
			Ksjieshou = true;
			Caozuofu = '=';
		}
		private System.Windows.Forms.TextBox txtOutput;
		private System.Windows.Forms.Button btnDivide;
		private System.Windows.Forms.Button btnMultiply;
		private System.Windows.Forms.Button btnSubstract;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnEquals;
		private System.Windows.Forms.Button buttona;
		private System.Windows.Forms.Button buttonb;
		private System.Windows.Forms.Button buttonc;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button0;
		private System.Windows.Forms.Button buttonmc;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.Button button8;
		private System.Windows.Forms.Button button9;
		private System.Windows.Forms.Button buttonmr;
		private System.Windows.Forms.Button buttonms;
		private System.Windows.Forms.Button buttonm;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.Button button10;
		private System.Windows.Forms.Button button11;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			EventHandler eh = new EventHandler(this.Numbers_Click);
			button0.Click += eh;
			button1.Click += eh;
			button2.Click += eh;
			button3.Click += eh;
			button4.Click += eh;
			button5.Click += eh;
			button6.Click += eh;
			button7.Click += eh;
			button8.Click += eh;
			button9.Click += eh;
			eh=new EventHandler(this.Operators_Click);
			btnAdd.Click +=eh;
			btnSubstract.Click +=eh;
			btnMultiply.Click +=eh;
			btnDivide.Click +=eh;
			btnEquals.Click +=eh;
            InitMembers();
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		private void InitMembers()
		{   Number =0;
			Caozuofu='=';
			Ksjieshou = true;
			Point = true;
			funot = true;
        }
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		
		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.buttona = new System.Windows.Forms.Button();
			this.buttonb = new System.Windows.Forms.Button();
			this.buttonc = new System.Windows.Forms.Button();
			this.buttonmc = new System.Windows.Forms.Button();
			this.button7 = new System.Windows.Forms.Button();
			this.button8 = new System.Windows.Forms.Button();
			this.button9 = new System.Windows.Forms.Button();
			this.btnDivide = new System.Windows.Forms.Button();
			this.buttonmr = new System.Windows.Forms.Button();
			this.buttonms = new System.Windows.Forms.Button();
			this.buttonm = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.button5 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.btnMultiply = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.btnSubstract = new System.Windows.Forms.Button();
			this.button0 = new System.Windows.Forms.Button();
			this.button10 = new System.Windows.Forms.Button();
			this.button11 = new System.Windows.Forms.Button();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnEquals = new System.Windows.Forms.Button();
			this.txtOutput = new System.Windows.Forms.TextBox();
			this.lblMem = new System.Windows.Forms.Label();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.SuspendLayout();
			// 
			// buttona
			// 
			this.buttona.ForeColor = System.Drawing.Color.Black;
			this.buttona.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
			this.buttona.Location = new System.Drawing.Point(208, 40);
			this.buttona.Name = "buttona";
			this.buttona.Size = new System.Drawing.Size(40, 24);
			this.buttona.TabIndex = 1;
			this.buttona.Text = "←";
			this.buttona.Click += new System.EventHandler(this.button1_Click);
			// 
			// buttonb
			// 
			this.buttonb.ForeColor = System.Drawing.Color.Red;
			this.buttonb.Location = new System.Drawing.Point(208, 72);
			this.buttonb.Name = "buttonb";
			this.buttonb.Size = new System.Drawing.Size(40, 24);
			this.buttonb.TabIndex = 2;
			this.buttonb.Text = "CE";
			this.buttonb.Click += new System.EventHandler(this.buttonb_Click);
			// 
			// buttonc
			// 
			this.buttonc.ForeColor = System.Drawing.Color.Red;
			this.buttonc.Location = new System.Drawing.Point(208, 104);
			this.buttonc.Name = "buttonc";
			this.buttonc.Size = new System.Drawing.Size(40, 24);
			this.buttonc.TabIndex = 3;
			this.buttonc.Text = "C";
			this.buttonc.Click += new System.EventHandler(this.buttonc_Click);
			// 
			// buttonmc
			// 
			this.buttonmc.ForeColor = System.Drawing.Color.Black;
			this.buttonmc.Location = new System.Drawing.Point(8, 40);
			this.buttonmc.Name = "buttonmc";
			this.buttonmc.Size = new System.Drawing.Size(32, 24);
			this.buttonmc.TabIndex = 4;
			this.buttonmc.Text = "MC";
			this.buttonmc.Click += new System.EventHandler(this.buttonmc_Click);
			// 
			// button7
			// 
			this.button7.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button7.Location = new System.Drawing.Point(48, 40);
			this.button7.Name = "button7";
			this.button7.Size = new System.Drawing.Size(32, 24);
			this.button7.TabIndex = 5;
			this.button7.Text = "7";
			this.button7.Click += new System.EventHandler(this.button5_Click);
			// 
			// button8
			// 
			this.button8.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button8.Location = new System.Drawing.Point(88, 40);
			this.button8.Name = "button8";
			this.button8.Size = new System.Drawing.Size(32, 24);
			this.button8.TabIndex = 6;
			this.button8.Text = "8";
			this.button8.Click += new System.EventHandler(this.button6_Click);
			// 
			// button9
			// 
			this.button9.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button9.Location = new System.Drawing.Point(128, 40);
			this.button9.Name = "button9";
			this.button9.Size = new System.Drawing.Size(32, 24);
			this.button9.TabIndex = 7;
			this.button9.Text = "9";
			this.button9.Click += new System.EventHandler(this.button7_Click);
			// 
			// btnDivide
			// 
			this.btnDivide.ForeColor = System.Drawing.Color.Black;
			this.btnDivide.Location = new System.Drawing.Point(168, 40);
			this.btnDivide.Name = "btnDivide";
			this.btnDivide.Size = new System.Drawing.Size(32, 24);
			this.btnDivide.TabIndex = 8;
			this.btnDivide.Text = "/";
			this.btnDivide.Click += new System.EventHandler(this.button8_Click);
			// 
			// buttonmr
			// 
			this.buttonmr.ForeColor = System.Drawing.Color.Black;
			this.buttonmr.Location = new System.Drawing.Point(8, 72);
			this.buttonmr.Name = "buttonmr";
			this.buttonmr.Size = new System.Drawing.Size(32, 24);
			this.buttonmr.TabIndex = 10;
			this.buttonmr.Text = "MR";
			this.buttonmr.Click += new System.EventHandler(this.buttonmr_Click);
			// 
			// buttonms
			// 
			this.buttonms.ForeColor = System.Drawing.Color.Black;
			this.buttonms.Location = new System.Drawing.Point(8, 104);
			this.buttonms.Name = "buttonms";
			this.buttonms.Size = new System.Drawing.Size(32, 24);
			this.buttonms.TabIndex = 11;
			this.buttonms.Text = "MS";
			this.buttonms.Click += new System.EventHandler(this.buttonms_Click);
			// 
			// buttonm
			// 
			this.buttonm.ForeColor = System.Drawing.Color.Black;
			this.buttonm.Location = new System.Drawing.Point(8, 136);
			this.buttonm.Name = "buttonm";
			this.buttonm.Size = new System.Drawing.Size(32, 24);
			this.buttonm.TabIndex = 12;
			this.buttonm.Text = "M+";
			this.buttonm.Click += new System.EventHandler(this.buttonm_Click);
			// 
			// button4
			// 
			this.button4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button4.Location = new System.Drawing.Point(48, 72);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(32, 24);
			this.button4.TabIndex = 13;
			this.button4.Text = "4";
			this.button4.Click += new System.EventHandler(this.button13_Click);
			// 
			// button5
			// 
			this.button5.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button5.Location = new System.Drawing.Point(88, 72);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(32, 24);
			this.button5.TabIndex = 14;
			this.button5.Text = "5";
			this.button5.Click += new System.EventHandler(this.button14_Click);
			// 
			// button6
			// 
			this.button6.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button6.Location = new System.Drawing.Point(128, 72);
			this.button6.Name = "button6";
			this.button6.Size = new System.Drawing.Size(32, 24);
			this.button6.TabIndex = 15;
			this.button6.Text = "6";
			this.button6.Click += new System.EventHandler(this.button15_Click);
			// 
			// btnMultiply
			// 
			this.btnMultiply.ForeColor = System.Drawing.Color.Black;
			this.btnMultiply.Location = new System.Drawing.Point(168, 72);
			this.btnMultiply.Name = "btnMultiply";
			this.btnMultiply.Size = new System.Drawing.Size(32, 24);
			this.btnMultiply.TabIndex = 16;
			this.btnMultiply.Text = "*";
			this.btnMultiply.Click += new System.EventHandler(this.button16_Click);
			// 
			// button1
			// 
			this.button1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button1.Location = new System.Drawing.Point(48, 104);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(32, 24);
			this.button1.TabIndex = 18;
			this.button1.Text = "1";
			this.button1.Click += new System.EventHandler(this.button18_Click);
			// 
			// button2
			// 
			this.button2.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button2.Location = new System.Drawing.Point(88, 104);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(32, 24);
			this.button2.TabIndex = 19;
			this.button2.Text = "2";
			this.button2.Click += new System.EventHandler(this.button19_Click);
			// 
			// button3
			// 
			this.button3.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button3.Location = new System.Drawing.Point(128, 104);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(32, 24);
			this.button3.TabIndex = 20;
			this.button3.Text = "3";
			this.button3.Click += new System.EventHandler(this.button20_Click);
			// 
			// btnSubstract
			// 
			this.btnSubstract.ForeColor = System.Drawing.Color.Black;
			this.btnSubstract.Location = new System.Drawing.Point(168, 104);
			this.btnSubstract.Name = "btnSubstract";
			this.btnSubstract.Size = new System.Drawing.Size(32, 24);
			this.btnSubstract.TabIndex = 21;
			this.btnSubstract.Text = "-";
			this.btnSubstract.Click += new System.EventHandler(this.button21_Click);
			// 
			// button0
			// 
			this.button0.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button0.Location = new System.Drawing.Point(48, 136);
			this.button0.Name = "button0";
			this.button0.Size = new System.Drawing.Size(32, 24);
			this.button0.TabIndex = 23;
			this.button0.Text = "0";
			this.button0.Click += new System.EventHandler(this.button23_Click);
			// 
			// button10
			// 
			this.button10.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button10.Location = new System.Drawing.Point(88, 136);
			this.button10.Name = "button10";
			this.button10.Size = new System.Drawing.Size(32, 24);
			this.button10.TabIndex = 24;
			this.button10.Text = "+/-";
			this.button10.Click += new System.EventHandler(this.button10_Click);
			// 
			// button11
			// 
			this.button11.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.button11.Location = new System.Drawing.Point(128, 136);
			this.button11.Name = "button11";
			this.button11.Size = new System.Drawing.Size(32, 24);
			this.button11.TabIndex = 25;
			this.button11.Text = ".";
			this.button11.Click += new System.EventHandler(this.button11_Click);
			// 
			// btnAdd
			// 
			this.btnAdd.ForeColor = System.Drawing.Color.Black;
			this.btnAdd.Location = new System.Drawing.Point(168, 136);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(32, 24);
			this.btnAdd.TabIndex = 26;
			this.btnAdd.Text = "+";
			this.btnAdd.Click += new System.EventHandler(this.button26_Click);
			// 
			// btnEquals
			// 
			this.btnEquals.ForeColor = System.Drawing.Color.Black;
			this.btnEquals.Location = new System.Drawing.Point(208, 136);
			this.btnEquals.Name = "btnEquals";
			this.btnEquals.Size = new System.Drawing.Size(40, 24);
			this.btnEquals.TabIndex = 27;
			this.btnEquals.Text = "=";
			this.btnEquals.Click += new System.EventHandler(this.button27_Click);
			// 
			// txtOutput
			// 
			this.txtOutput.Location = new System.Drawing.Point(8, 8);
			this.txtOutput.MaxLength = 10;
			this.txtOutput.Name = "txtOutput";
			this.txtOutput.ReadOnly = true;
			this.txtOutput.Size = new System.Drawing.Size(184, 21);
			this.txtOutput.TabIndex = 29;
			this.txtOutput.Text = "0.";
			this.txtOutput.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// lblMem
			// 
			this.lblMem.Location = new System.Drawing.Point(208, 8);
			this.lblMem.Name = "lblMem";
			this.lblMem.Size = new System.Drawing.Size(32, 24);
			this.lblMem.TabIndex = 30;
			this.lblMem.Text = "M";
			this.lblMem.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			this.lblMem.Visible = false;
			this.lblMem.Click += new System.EventHandler(this.lblMem_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(256, 168);
			this.Controls.Add(this.lblMem);
			this.Controls.Add(this.txtOutput);
			this.Controls.Add(this.btnEquals);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.button11);
			this.Controls.Add(this.button10);
			this.Controls.Add(this.button0);
			this.Controls.Add(this.btnSubstract);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.btnMultiply);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -