最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#編寫的windows計算器的實例代碼

 更新時間:2013年07月23日 10:29:55   投稿:shangke  
這篇文章介紹了C#編寫windows計算器的代碼,有需要的朋友可以參考一下

復制代碼 代碼如下:

using System;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Data;
namespace comput
{
    /// <summary>
    /// 這是一個計算器的簡單實現(xiàn)。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        #region 控件聲明
        private System.Windows.Forms.TextBox txtShow;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button btn_rev;
        private System.Windows.Forms.Button btn_dot;
        private System.Windows.Forms.Button btn_add;
        private System.Windows.Forms.Button btn_equ;
        private System.Windows.Forms.Button btn_sign;
        private System.Windows.Forms.Button btn_sub;
        private System.Windows.Forms.Button btn_mul;
        private System.Windows.Forms.Button btn_0;
        private System.Windows.Forms.Button btn_3;
        private System.Windows.Forms.Button btn_2;
        private System.Windows.Forms.Button btn_1;
        private System.Windows.Forms.Button btn_6;
        private System.Windows.Forms.Button btn_5;
        private System.Windows.Forms.Button btn_4;
        private System.Windows.Forms.Button btn_sqrt;
        private System.Windows.Forms.Button btn_div;
        private System.Windows.Forms.Button btn_7;
        private System.Windows.Forms.Button btn_8;
        private System.Windows.Forms.Button btn_9;
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem menuItem1;
        private System.Windows.Forms.Button btn_sqr;
        private System.Windows.Forms.MenuItem menuItem2;
        private System.Windows.Forms.MenuItem menuItem3;
        private System.Windows.Forms.MenuItem menuItem4;
        private System.Windows.Forms.MenuItem menuItem5;
        private System.Windows.Forms.MenuItem menuItem6;
        private System.Windows.Forms.Button c;
        private System.Windows.Forms.Button ce;
        private System.Windows.Forms.MenuItem menuItem8;
        private System.Windows.Forms.MenuItem menuItem9;
        private System.Windows.Forms.MenuItem menuItem10;
        /// <summary>
        /// 必需的設計器變量。
        /// </summary>
        private System.ComponentModel.Container components = null;
        public Form1()
        {
            //
            // Windows 窗體設計器支持所必需的
            //
            InitializeComponent();
            //
            // TODO: 在 InitializeComponent 調用后添加任何構造函數(shù)代碼
            //
        }
        /// <summary>
        /// 清理所有正在使用的資源。
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
       #endregion
        #region 各控件的屬性的方法Windows Form Designer generated code
        /// <summary>
        /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
        /// 此方法的內容。
        /// </summary>
        private void InitializeComponent()
        {
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
            this.txtShow = new System.Windows.Forms.TextBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.c = new System.Windows.Forms.Button();
            this.ce = new System.Windows.Forms.Button();
            this.btn_rev = new System.Windows.Forms.Button();
            this.btn_dot = new System.Windows.Forms.Button();
            this.btn_add = new System.Windows.Forms.Button();
            this.btn_equ = new System.Windows.Forms.Button();
            this.btn_sign = new System.Windows.Forms.Button();
            this.btn_sub = new System.Windows.Forms.Button();
            this.btn_mul = new System.Windows.Forms.Button();
            this.btn_0 = new System.Windows.Forms.Button();
            this.btn_3 = new System.Windows.Forms.Button();
            this.btn_2 = new System.Windows.Forms.Button();
            this.btn_1 = new System.Windows.Forms.Button();
            this.btn_6 = new System.Windows.Forms.Button();
            this.btn_5 = new System.Windows.Forms.Button();
            this.btn_4 = new System.Windows.Forms.Button();
            this.btn_sqrt = new System.Windows.Forms.Button();
            this.btn_div = new System.Windows.Forms.Button();
            this.btn_7 = new System.Windows.Forms.Button();
            this.btn_8 = new System.Windows.Forms.Button();
            this.btn_9 = new System.Windows.Forms.Button();
            this.btn_sqr = new System.Windows.Forms.Button();
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.menuItem5 = new System.Windows.Forms.MenuItem();
            this.menuItem6 = new System.Windows.Forms.MenuItem();
            this.menuItem8 = new System.Windows.Forms.MenuItem();
            this.menuItem9 = new System.Windows.Forms.MenuItem();
            this.menuItem10 = new System.Windows.Forms.MenuItem();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            //
            // txtShow
            //
            this.txtShow.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
            this.txtShow.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.txtShow.ForeColor = System.Drawing.Color.Purple;
            this.txtShow.Location = new System.Drawing.Point(25, 8);
            this.txtShow.Name = "txtShow";
            this.txtShow.Size = new System.Drawing.Size(228, 23);
            this.txtShow.TabIndex = 1;
            this.txtShow.Text = "0.";
            this.txtShow.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.c);
            this.groupBox1.Controls.Add(this.ce);
            this.groupBox1.Controls.Add(this.btn_rev);
            this.groupBox1.Controls.Add(this.btn_dot);
            this.groupBox1.Controls.Add(this.btn_add);
            this.groupBox1.Controls.Add(this.btn_equ);
            this.groupBox1.Controls.Add(this.btn_sign);
            this.groupBox1.Controls.Add(this.btn_sub);
            this.groupBox1.Controls.Add(this.btn_mul);
            this.groupBox1.Controls.Add(this.btn_0);
            this.groupBox1.Controls.Add(this.btn_3);
            this.groupBox1.Controls.Add(this.btn_2);
            this.groupBox1.Controls.Add(this.btn_1);
            this.groupBox1.Controls.Add(this.btn_6);
            this.groupBox1.Controls.Add(this.btn_5);
            this.groupBox1.Controls.Add(this.btn_4);
            this.groupBox1.Controls.Add(this.btn_sqrt);
            this.groupBox1.Controls.Add(this.btn_div);
            this.groupBox1.Controls.Add(this.btn_7);
            this.groupBox1.Controls.Add(this.btn_8);
            this.groupBox1.Controls.Add(this.btn_9);
            this.groupBox1.Controls.Add(this.btn_sqr);
            this.groupBox1.Location = new System.Drawing.Point(24, 40);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(232, 184);
            this.groupBox1.TabIndex = 21;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "計算機區(qū)";
            //
            // c
            //
            this.c.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.c.ForeColor = System.Drawing.Color.Red;
            this.c.Location = new System.Drawing.Point(178, 48);
            this.c.Name = "c";
            this.c.Size = new System.Drawing.Size(36, 61);
            this.c.TabIndex = 41;
            this.c.Text = "C";
            this.c.Click += new System.EventHandler(this.btn_Oper);
            //
            // ce
            //
            this.ce.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.ce.ForeColor = System.Drawing.Color.Red;
            this.ce.Location = new System.Drawing.Point(138, 16);
            this.ce.Name = "ce";
            this.ce.Size = new System.Drawing.Size(76, 29);
            this.ce.TabIndex = 40;
            this.ce.Text = "CE";
            this.ce.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_rev
            //
            this.btn_rev.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_rev.ForeColor = System.Drawing.Color.Blue;
            this.btn_rev.Location = new System.Drawing.Point(178, 112);
            this.btn_rev.Name = "btn_rev";
            this.btn_rev.Size = new System.Drawing.Size(36, 29);
            this.btn_rev.TabIndex = 39;
            this.btn_rev.Text = "1/x";
            this.btn_rev.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_dot
            //
            this.btn_dot.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_dot.Location = new System.Drawing.Point(98, 144);
            this.btn_dot.Name = "btn_dot";
            this.btn_dot.Size = new System.Drawing.Size(36, 29);
            this.btn_dot.TabIndex = 38;
            this.btn_dot.Tag = "0";
            this.btn_dot.Text = ".";
            this.btn_dot.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_add
            //
            this.btn_add.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_add.ForeColor = System.Drawing.Color.Red;
            this.btn_add.Location = new System.Drawing.Point(138, 144);
            this.btn_add.Name = "btn_add";
            this.btn_add.Size = new System.Drawing.Size(36, 29);
            this.btn_add.TabIndex = 37;
            this.btn_add.Text = "+";
            this.btn_add.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_equ
            //
            this.btn_equ.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_equ.ForeColor = System.Drawing.Color.Red;
            this.btn_equ.Location = new System.Drawing.Point(178, 144);
            this.btn_equ.Name = "btn_equ";
            this.btn_equ.Size = new System.Drawing.Size(36, 29);
            this.btn_equ.TabIndex = 36;
            this.btn_equ.Text = "=";
            this.btn_equ.Click += new System.EventHandler(this.btn_equ_Click);
            //
            // btn_sign
            //
            this.btn_sign.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_sign.ForeColor = System.Drawing.Color.Blue;
            this.btn_sign.Location = new System.Drawing.Point(58, 144);
            this.btn_sign.Name = "btn_sign";
            this.btn_sign.Size = new System.Drawing.Size(36, 29);
            this.btn_sign.TabIndex = 35;
            this.btn_sign.Text = "+/-";
            this.btn_sign.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_sub
            //
            this.btn_sub.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_sub.ForeColor = System.Drawing.Color.Red;
            this.btn_sub.Location = new System.Drawing.Point(138, 112);
            this.btn_sub.Name = "btn_sub";
            this.btn_sub.Size = new System.Drawing.Size(36, 29);
            this.btn_sub.TabIndex = 34;
            this.btn_sub.Text = "-";
            this.btn_sub.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_mul
            //
            this.btn_mul.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_mul.ForeColor = System.Drawing.Color.Red;
            this.btn_mul.Location = new System.Drawing.Point(138, 80);
            this.btn_mul.Name = "btn_mul";
            this.btn_mul.Size = new System.Drawing.Size(36, 29);
            this.btn_mul.TabIndex = 33;
            this.btn_mul.Text = "*";
            this.btn_mul.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_0
            //
            this.btn_0.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_0.ForeColor = System.Drawing.Color.Blue;
            this.btn_0.Location = new System.Drawing.Point(18, 144);
            this.btn_0.Name = "btn_0";
            this.btn_0.Size = new System.Drawing.Size(36, 29);
            this.btn_0.TabIndex = 32;
            this.btn_0.Tag = "0";
            this.btn_0.Text = "0";
            this.btn_0.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_3
            //
            this.btn_3.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_3.ForeColor = System.Drawing.Color.Blue;
            this.btn_3.Location = new System.Drawing.Point(98, 112);
            this.btn_3.Name = "btn_3";
            this.btn_3.Size = new System.Drawing.Size(36, 29);
            this.btn_3.TabIndex = 31;
            this.btn_3.Tag = "3";
            this.btn_3.Text = "3";
            this.btn_3.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_2
            //
            this.btn_2.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_2.ForeColor = System.Drawing.Color.Blue;
            this.btn_2.Location = new System.Drawing.Point(58, 112);
            this.btn_2.Name = "btn_2";
            this.btn_2.Size = new System.Drawing.Size(36, 29);
            this.btn_2.TabIndex = 30;
            this.btn_2.Tag = "2";
            this.btn_2.Text = "2";
            this.btn_2.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_1
            //
            this.btn_1.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_1.ForeColor = System.Drawing.Color.Blue;
            this.btn_1.Location = new System.Drawing.Point(18, 112);
            this.btn_1.Name = "btn_1";
            this.btn_1.Size = new System.Drawing.Size(36, 29);
            this.btn_1.TabIndex = 29;
            this.btn_1.Tag = "1";
            this.btn_1.Text = "1";
            this.btn_1.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_6
            //
            this.btn_6.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_6.ForeColor = System.Drawing.Color.Blue;
            this.btn_6.Location = new System.Drawing.Point(98, 80);
            this.btn_6.Name = "btn_6";
            this.btn_6.Size = new System.Drawing.Size(36, 29);
            this.btn_6.TabIndex = 28;
            this.btn_6.Tag = "6";
            this.btn_6.Text = "6";
            this.btn_6.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_5
            //
            this.btn_5.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_5.ForeColor = System.Drawing.Color.Blue;
            this.btn_5.Location = new System.Drawing.Point(58, 80);
            this.btn_5.Name = "btn_5";
            this.btn_5.Size = new System.Drawing.Size(36, 29);
            this.btn_5.TabIndex = 27;
            this.btn_5.Tag = "5";
            this.btn_5.Text = "5";
            this.btn_5.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_4
            //
            this.btn_4.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_4.ForeColor = System.Drawing.Color.Blue;
            this.btn_4.Location = new System.Drawing.Point(18, 80);
            this.btn_4.Name = "btn_4";
            this.btn_4.Size = new System.Drawing.Size(36, 29);
            this.btn_4.TabIndex = 26;
            this.btn_4.Tag = "4";
            this.btn_4.Text = "4";
            this.btn_4.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_sqrt
            //
            this.btn_sqrt.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_sqrt.ForeColor = System.Drawing.Color.Blue;
            this.btn_sqrt.Location = new System.Drawing.Point(18, 16);
            this.btn_sqrt.Name = "btn_sqrt";
            this.btn_sqrt.Size = new System.Drawing.Size(76, 29);
            this.btn_sqrt.TabIndex = 25;
            this.btn_sqrt.Text = "sqrt";
            this.btn_sqrt.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_div
            //
            this.btn_div.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_div.ForeColor = System.Drawing.Color.Red;
            this.btn_div.Location = new System.Drawing.Point(138, 48);
            this.btn_div.Name = "btn_div";
            this.btn_div.Size = new System.Drawing.Size(36, 29);
            this.btn_div.TabIndex = 24;
            this.btn_div.Text = "/";
            this.btn_div.Click += new System.EventHandler(this.btn_Oper);
            //
            // btn_7
            //
            this.btn_7.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_7.ForeColor = System.Drawing.Color.Blue;
            this.btn_7.Location = new System.Drawing.Point(18, 48);
            this.btn_7.Name = "btn_7";
            this.btn_7.Size = new System.Drawing.Size(36, 29);
            this.btn_7.TabIndex = 23;
            this.btn_7.Tag = "7";
            this.btn_7.Text = "7";
            this.btn_7.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_8
            //
            this.btn_8.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_8.ForeColor = System.Drawing.Color.Blue;
            this.btn_8.Location = new System.Drawing.Point(58, 48);
            this.btn_8.Name = "btn_8";
            this.btn_8.Size = new System.Drawing.Size(36, 29);
            this.btn_8.TabIndex = 22;
            this.btn_8.Tag = "8";
            this.btn_8.Text = "8";
            this.btn_8.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_9
            //
            this.btn_9.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_9.ForeColor = System.Drawing.Color.Blue;
            this.btn_9.Location = new System.Drawing.Point(98, 48);
            this.btn_9.Name = "btn_9";
            this.btn_9.Size = new System.Drawing.Size(36, 29);
            this.btn_9.TabIndex = 21;
            this.btn_9.Tag = "9";
            this.btn_9.Text = "9";
            this.btn_9.Click += new System.EventHandler(this.btn_0_Click);
            //
            // btn_sqr
            //
            this.btn_sqr.Font = new System.Drawing.Font("宋體", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
            this.btn_sqr.ForeColor = System.Drawing.Color.Blue;
            this.btn_sqr.Location = new System.Drawing.Point(98, 16);
            this.btn_sqr.Name = "btn_sqr";
            this.btn_sqr.Size = new System.Drawing.Size(36, 29);
            this.btn_sqr.TabIndex = 19;
            this.btn_sqr.Text = "sqr";
            this.btn_sqr.Click += new System.EventHandler(this.btn_Oper);
            //
            // mainMenu1
            //
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem8,
                                                                                      this.menuItem1,
                                                                                      this.menuItem4});
            //
            // menuItem1
            //
            this.menuItem1.Index = 1;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem2,
                                                                                      this.menuItem3});
            this.menuItem1.Text = "編輯(&E)";
            //
            // menuItem2
            //
            this.menuItem2.Index = 0;
            this.menuItem2.Text = "復制(&C)";
            this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
            //
            // menuItem3
            //
            this.menuItem3.Index = 1;
            this.menuItem3.Text = "粘貼(&P)";
            this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
            //
            // menuItem4
            //
            this.menuItem4.Index = 2;
            this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem5,
                                                                                      this.menuItem6});
            this.menuItem4.Text = "幫助(&H)";
            //
            // menuItem5
            //
            this.menuItem5.Index = 0;
            this.menuItem5.Text = "幫助主題(&H)";
            this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
            //
            // menuItem6
            //
            this.menuItem6.Index = 1;
            this.menuItem6.Text = "關于(&A)";
            this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
            //
            // menuItem8
            //
            this.menuItem8.Index = 0;
            this.menuItem8.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem9,
                                                                                      this.menuItem10});
            this.menuItem8.Text = "文件(&F)";
            //
            // menuItem9
            //
            this.menuItem9.Index = 0;
            this.menuItem9.Text = "打開windows計算器(&O)";
            this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
            //
            // menuItem10
            //
            this.menuItem10.Index = 1;
            this.menuItem10.Text = "退出(&Q)";
            this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(278, 239);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.txtShow);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Menu = this.mainMenu1;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "計算器";
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
        }
        #endregion
        #region 各變量和常數(shù)的聲明
        public const int NULL = 0;      // 定義操作碼
        public const int ADD = 1;     //表示加
        public const int SUB = 2;     //減
        public const int MUL = 3;     //乘
        public const int DIV = 4;    //除
        public const int SQR = 5;    //求平方
        public const int SQRT = 6;   //求平方根
        public const int NODOT  = 0;     // 定義是否點擊了小數(shù)點,0 為沒點
        public const int HASDOT = 1;
        private double res = 0;         // 記錄結果數(shù)
        private double tmp = 0;         // 當前輸入的操作數(shù)
        private int opt = NULL;         // 記錄操作碼
        private int dot = NODOT;    // 記錄是否點擊了小數(shù)點,0為沒有點
        private int num = 0;        // 記錄輸入操作數(shù)的個數(shù)
        private int dotnum = 0;        // 記錄小數(shù)點部分的個數(shù)       
        string strOper;            //獲取操作符
        #endregion
        /// <summary>
        /// 應用程序的主入口點。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }
        /// <summary>
        #region 獲取操作數(shù)事件
        //獲取操作數(shù)事件
        private void btn_0_Click(object sender, System.EventArgs e)
        {
            System.Windows.Forms.Button btnTmp;
            double i;
            btnTmp = sender as System.Windows.Forms.Button;           
            if (btnTmp != null)
            {
                if (dot == NODOT)
                {
                    // 沒有點擊小數(shù)點
                    i = double.Parse(btnTmp.Tag.ToString()); //取用戶自定義的控件關聯(lián)數(shù),并轉換成double型
                    tmp = tmp * 10 + i;
                    txtShow.Text = tmp.ToString();   //將其放入文本顯示屏啊
                }
                else   // 點擊了小數(shù)點
                {                   
                    dotnum++;    //記錄小數(shù)點部分的個數(shù)
                                                       // 生成小數(shù)部分的新的數(shù)值
                    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);
                    tmp = tmp + i;  //將小數(shù)點后的值加到當前操做數(shù)
                    txtShow.Text = tmp.ToString();
                }
            }
        }
        #endregion
        #region 等于事件和等于運算方法
        //等于事件
        private void btn_equ_Click(object sender, System.EventArgs e)
        {
            calc();
        }
        //等于運算方法
        private void calc()
        {
            // 生成結果
            if (num == 0 )    //是否有操作數(shù),沒有就返回0
            {
                res = 0;
                tmp = 0;
                txtShow.Text = res.ToString();
                return;
            }
            switch (opt)  //找到對應的運算符進行計算
            {
                    // 加法
                case ADD:
                    res = res + tmp;                   
                    break;
                    // 減法
                case SUB:
                    res = res - tmp;                   
                    break;
                    // 乘法
                case MUL:
                    res = res * tmp;                   
                    break;
                    // 除法
                case DIV:
                    res = res / tmp;                   
                    break;
                    // 平方
                case SQR:
                    res = tmp * tmp;                   
                    break;
                    // 平方根
                case SQRT:
                    res = System.Math.Sqrt(tmp);                   
                    break;
                default:
                    return;
            }
            txtShow.Text = res.ToString();   //結果輸出到文本顯示屏
            opt = NULL;  //運算符清空
            tmp=0;   
            dot = NODOT;
                    //res = 0;
                    //num = 0;
        }
        #endregion
        #region 獲取操作符運事件
        //獲取操作符運事件
        private void btn_Oper(object obj,EventArgs ea)
        {
            Button tmp1=(Button)obj;
            strOper=tmp1.Text;
            switch (strOper)
            {
                case "/":       //除法運算
                    if(opt!=NULL&&opt!=DIV)
                    {
                        calc();
                    }
                    opt = DIV;
                    if (num != 0)  //判斷操作數(shù)的個數(shù),如果兩個就做二元運算
                    {
                        if (tmp != 0)
                            res = res / tmp;
                    }
                    else
                        res = tmp;
                    num++;                     
                    tmp = 0;
                    txtShow.Text = res.ToString();
                    dot = NODOT;
                    break;
                case "*":
                    // 乘法運算
                    if(opt!=NULL&&opt!=MUL)
                    {
                        calc();
                    }
                    opt = MUL;
                    if (num!= 0 )     //判斷操作數(shù)的個數(shù),如果兩個就做二元運算   
                    {
                            if(tmp!=0)
                         res = res * tmp;
                    }
                    else
                        res = tmp;
                    num++;                                     
                    tmp = 0;
                    txtShow.Text = res.ToString();
                    dot = NODOT;
                    break;
                case "+":            //加法運算
                    if(opt!=NULL&&opt!=ADD)
                    {
                        calc();
                    }
                    opt = ADD;
                    if (num != 0)    //判斷操作數(shù)的個數(shù),如果兩個就做二元運算
                        res = res + tmp;
                    else
                        res = tmp;
                    num++;                   
                    tmp = 0;
                    txtShow.Text = res.ToString();
                    dot = NODOT;
                    break;
                case "-":        //減法運算
                    if(opt!=NULL&&opt!=SUB)
                    {
                        calc();
                    }
                    /*if(opt==ADD)
                    {
                        res=res+tmp;
                        tmp=0;
                    }*/
                    opt = SUB;
                    if (num != 0)    //判斷操作數(shù)的個數(shù),如果兩個就做二元運算
                        res = res - tmp;
                    else
                        res = tmp;
                    num++;                    
                    tmp = 0;
                    txtShow.Text = res.ToString();
                    dot = NODOT;
                    break;
                case "sqrt":     //平方根運算
                    if(opt!=NULL)
                    {
                        calc();
                    }
                    //opt=SQRT;
                    if (tmp > 0)  //要求操作數(shù)大于0
                    {
                        res = Math.Sqrt(tmp);
                        //res=tmp;
                    }
                    else if(res>0)
                        res= Math.Sqrt(res);
                        txtShow.Text =res.ToString();
                    num++;   
                    tmp=0;
                    dot = NODOT;
                    break;
                case "sqr":
                    // 平方運算
                    if(opt!=NULL)
                    {
                        calc();
                    }
                    //opt=SQR;
                    if (tmp != 0)
                    {
                        res = tmp * tmp;
                        //res=tmp;
                    }
                    else
                        res=res*res;
                    txtShow.Text = res.ToString();
                    num++;   
                    tmp=0;
                    dot = NODOT;
                    break;
                case "1/x":  //倒數(shù)運算
                    if(opt!=NULL)
                    {
                        calc();
                    }
                    if (tmp != 0)
                    {
                        res = 1 / tmp;
                        //res=tmp;
                    }
                    else                   
                    res=1/res;
                    txtShow.Text = res.ToString();
                    tmp=0;
                    dot = NODOT;
                    break;
                case ".":
                            // 點擊了小數(shù)點
                    if(dot==HASDOT)
                        return;
                    else
                    {
                        dot = HASDOT;
                        dotnum = 0;
                    }                   
                    break;
                case "+/-":
                                // 點擊了符號運算
                    if(tmp!=0)
                    {
                        tmp = -tmp;
                        txtShow.Text = tmp.ToString();
                    }
                    else
                    {
                        res=-res;
                        //res=tmp;
                        txtShow.Text = res.ToString();   
                    }
                    dot = NODOT;
                    break;   
                case "CE":     //清除運算
                    res = 0;         // 記錄結果數(shù)
                    tmp = 0;         // 當前輸入的操作數(shù)
                    opt = NULL;         // 記錄操作碼
                    dot = NODOT;    // 記錄是否點擊了小數(shù)點
                    num = 0;        // 記錄輸入操作數(shù)的個數(shù)
                    dotnum = 0;        // 記錄小數(shù)點部分的個數(shù)
                    txtShow.Text="";                   
                    break;
                case "C":         //清除運算
                    res = 0;         // 記錄結果數(shù)
                    tmp = 0;         // 當前輸入的操作數(shù)
                    opt = NULL;         // 記錄操作碼
                    dot = NODOT;    // 記錄是否點擊了小數(shù)點
                    num = 0;        // 記錄輸入操作數(shù)的個數(shù)
                    dotnum = 0;        // 記錄小數(shù)點部分的個數(shù)
                    txtShow.Text="";
                    break;
            }
        }
        #endregion
        #region     主菜單事件
        //打開關于主題---調用windows xp中計算器的幫助
        private void menuItem5_Click(object sender, System.EventArgs e)
        {
            Help.ShowHelp(this,"C:\\WINDOWS\\Help\\calc.chm");       
        }
        //打開于我們
        private void menuItem6_Click(object sender, System.EventArgs e)
        {
            Form2 fm=new Form2();
            fm.Show();
        }
        //復制
        private void menuItem2_Click(object sender, System.EventArgs e)
        {
            if(txtShow.SelectionLength>0)
            {
                txtShow.Copy();
            }
        }
        //
       //粘貼
        private void menuItem3_Click(object sender, System.EventArgs e)
        {
            txtShow.Paste();
        }
          //調用windows xp中的計算器
        private void menuItem9_Click(object sender, System.EventArgs e)
        {
             Help.ShowHelp(this,"C:\\WINDOWS\\system32\\calc.exe");
        }
        //退出
        private void menuItem10_Click(object sender, System.EventArgs e)
        {
            Application.Exit();
        }
        #endregion
    }
}

PS:這里再為大家推薦兩款本站的在線計算器,都是采用js實現(xiàn),相信對大家有一定借鑒作用:

在線標準計算器:http://tools.jb51.net/jisuanqi/jsq

在線科學計算器:http://tools.jb51.net/jisuanqi/jsqkexue

相關文章

  • C#實現(xiàn)運行狀態(tài)堆疊柱狀圖

    C#實現(xiàn)運行狀態(tài)堆疊柱狀圖

    這篇文章主要為大家詳細介紹了C#實現(xiàn)運行狀態(tài)堆疊柱狀圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • C#中環(huán)境變量示例詳解

    C#中環(huán)境變量示例詳解

    環(huán)境變量是操作系統(tǒng)中存儲的一種機制,用于保存與操作系統(tǒng)環(huán)境和應用程序運行相關的配置信息,在 C# 中,可以使用 Environment.GetEnvironmentVariable 方法來獲取特定環(huán)境變量的值,下面給大家介紹C#中環(huán)境變量示例代碼,一起看看吧
    2024-05-05
  • C#私有構造函數(shù)使用示例

    C#私有構造函數(shù)使用示例

    本文主要介紹了C#私有構造函數(shù)使用方法,私有構造函數(shù)是一種特殊的實例構造函數(shù)。它通常用在只包含靜態(tài)成員的類中。如果類具有一個或多個私有構造函數(shù)而沒有公共構造函數(shù),則其他類(除嵌套類外)無法創(chuàng)建該類的實例
    2014-01-01
  • C#多線程TPL模式高級用法探秘

    C#多線程TPL模式高級用法探秘

    本文詳細講解了C#多線程TPL模式的高級用法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • Entity?Framework代碼優(yōu)先(Code?First)模式

    Entity?Framework代碼優(yōu)先(Code?First)模式

    這篇文章介紹了Entity?Framework代碼優(yōu)先(Code?First)模式,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • 關于C#中的Invoke示例詳解

    關于C#中的Invoke示例詳解

    一直對invoke和begininvoke的使用和概念比較混亂,這兩天看了些資料,對這兩個的用法和原理有了些新的認識和理解,下面這篇文章主要給大家介紹了關于C#中Invoke的相關資料,需要的朋友可以參考下
    2023-02-02
  • 淺析C# 中的類型系統(tǒng)(值類型和引用類型)

    淺析C# 中的類型系統(tǒng)(值類型和引用類型)

    這篇文章主要介紹了淺析C# 中的類型系統(tǒng)(值類型和引用類型),需要的朋友可以參考下
    2017-02-02
  • C#圖像灰度級拉伸的方法

    C#圖像灰度級拉伸的方法

    這篇文章主要介紹了C#圖像灰度級拉伸的方法,涉及C#灰度操作的相關技巧,需要的朋友可以參考下
    2015-04-04
  • C#中執(zhí)行批處理文件(*.bat)的方法代碼

    C#中執(zhí)行批處理文件(*.bat)的方法代碼

    本文介紹一下在C#中執(zhí)行批處理文件(*.bat)的方法。
    2013-03-03
  • C#如何獲取計算機信息

    C#如何獲取計算機信息

    這篇文章主要為大家詳細介紹了C#獲取計算機信息的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07

最新評論

光山县| 沛县| 文山县| 柘城县| 满洲里市| 措美县| 墨竹工卡县| 金沙县| 马龙县| 巴青县| 江川县| 那坡县| 桃江县| 沂南县| 浦城县| 仁化县| 荣成市| 扎兰屯市| 民县| 安福县| 正镶白旗| 若羌县| 荃湾区| 海城市| 石泉县| 蕲春县| 巨鹿县| 西藏| 湄潭县| 雷州市| 乌兰察布市| 健康| 兴安县| 丰镇市| 东兰县| 缙云县| 商洛市| 勃利县| 年辖:市辖区| 鹤山市| 河西区|