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

📄 jisuanqi.txt

📁 这是一款用C#编写的可在windows下运行的计算器
💻 TXT
📖 第 1 页 / 共 3 页
字号:
            // 
            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 各变量和常数的声明
        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;     // 定义是否点击了小数点,0 为没点
        public const int HASDOT = 1;
        private double res = 0;         // 记录结果数
        private double tmp = 0;         // 当前输入的操作数
        private int opt = NULL;         // 记录操作码
        private int dot = NODOT;    // 记录是否点击了小数点,0为没有点
        private int num = 0;        // 记录输入操作数的个数
        private int dotnum = 0;        // 记录小数点部分的个数        
        string strOper;            //获取操作符
        #endregion
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        /// <summary>
        
        #region 获取操作数事件
        //获取操作数事件
        
        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)
                {
                    // 没有点击小数点
                    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型
                    tmp = tmp * 10 + i;
                    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊
                }
                else   // 点击了小数点
                {                    
                    dotnum++;    //记录小数点部分的个数
                                                       // 生成小数部分的新的数值
                    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);
                    tmp = tmp + i;  //将小数点后的值加到当前操做数
                    txtShow.Text = tmp.ToString();
                }
            }
        }
        #endregion

        #region 等于事件和等于运算方法
        //等于事件
        private void btn_equ_Click(object sender, System.EventArgs e)
        {
            calc();
        }

        //等于运算方法
        private void calc()
        {
            // 生成结果
            if (num == 0 )    //是否有操作数,没有就返回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:

⌨️ 快捷键说明

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