Windows计算器的制作(C#)

四则运算计算器程序 为一款经典的程序编写练习,四则运算计算器程序是C#编程中的一个非常好的入门练习。在本篇文章中,我们将为大家介绍如何用C#编写一个简单的四则运算计算器程序。通过编写四则运算计算器程序,我们可以掌握基本的C#编程知识,了解程序编写的基本思路和方法。同时,这个练习也让我们感受到了编程的乐趣和挑战。希望本篇文章能够对大家的C#编程学习有所帮助,也欢迎大家去探索更加复杂的计算器程序和其他有趣的应用! 阅读详情

1、按钮(Button)控件:

在Form1窗体中,添加30个Button控件,其中有10个数字按钮,16个运算按钮,一个用于计算的等号按钮,2个用于清空的按钮。

在Form2窗体中,添加17个Button控件,其中有10个数字按钮,4个运算按钮,一个用于计算的等号按钮,一个用于清空的按钮。

2、文本框(TextBox)控件:

Form1和Form2中分别添加一个TextBox控件,用于显示计算机的结果。

3、菜单栏(MunuStrip)控件:

在Form1和Form2中分别添加MenuStrip控件,并修改该控件中的ToolStripMunuItem菜单项的Text属性为“机型转换”。该控件可以实现两个窗体之间的相互转换。

打开Visual  Studio 2022,点击“创建新项目”

 在C#--Windows--桌面,选择Windows窗体应用(.Net Framework),点击“下一步”。

在配置新项目中,项目名称上,输入Calculator,点击“创建”。

添加两个窗体控件Form1和Form2,分别 用来表示科学计算器和普通计算器。

在右上角的《解决方案资源管理器》,鼠标放在Calculator单词字样,点击右键,选择“添加"--“窗体(Windows窗体)”。

在《添加新项》中,选择“窗体(Windows窗体)”,名称默认:Form2.cs,点击“添加”。

 

创建一个新的窗体控件Form2。

 

 左侧有“工具箱”,点击“菜单和工具栏”,点击“MenuStrip”。

在Form1上添加MenuStrip控件,并修改该控件中的ToolStripMenuItem菜单项的Text属性为“机型转换”。

ToolStripMenuItem菜单项的Text属性为“机型转换”。

在Form2上添加MenuStrip控件,并修改该控件中的ToolStripMenuItem菜单项的Text属性为“机型转换”。

ToolStripMenuItem菜单项的Text属性为“机型转换”。

Form1和Form2都有MenuStrip控件,该控件可以实现两个窗体之间的相互转换。 

在Form1的机型转换ToolStripMenuItem创建Click事件,双击一下。

 

 Form1的代码之前:

 

 Form2的代码之后:

 

在Form2的机型转换ToolStripMenuItem创建Click事件,双击一下。

 Form2的代码之前:

 Form2的代码之后:

 在Form1和Form2添加一个TextBox控件,用于显示计算结果。

在工具箱,公共控件中,点击TextBox。

 Form1:

 

Form2:

 在工具箱里,在公共控件中,点击Button。 

在Form1窗体中,添加30个Button控件,其中有10个数字按钮,16个运算按钮,一个用于计算的等号按钮,2个用于清空的按钮。

数字0~9的功能设计:对于计算机来说,当单击某个数字按钮后,结果显示区内应显示该按钮上的数字。

添加1的Button控件: 

Name的属性,原本是Button1,在Name修改为BtNumber1。 

Text的属性改为1

0,2-9,与上面的1方法一样。

在BtNumber1创建Click事件,双击。或者说,可以双击按钮1,切换到代码编程器。

 

代码之前:

 

代码之后:

代码中出现Op1的下面有红色波浪线,应该在public form1()的上面,产生新的变量。

 在代码中,数字键0~9只需将上述代码中的1改为相应的数字

小数点功能设计: 

添加Button控件: 

Text属性修改为. 

Name属性修改为BtComma

 BtComma的属性:

输入下列代码:

 

 等于的设计:

添加Button控件:

 

Text属性修改为=

 Name属性修改为BtDebgyu

 输入下代代码:

出现红色的波浪线,在publuc Form1的上面设置新的变量。 

添加变量以后,出现 有三处红色的波浪线:

 

后来找到了,缺少break;用错单词,把DialogResult改为result

加减乘除的设计加设计

添加6个Button,Text属性分别 是+,-,*,/,%和^。Name属性分别是BtAdd、BtSubtract、BtMult、BtDivision、BtRemedial和BtPower。 

 

全部都发生Click事件,输入下列代码: 

 

Del设计: 

新键一个Button控件,Text属性是Del,Name属性是BtDel。 

发生Click事件,输入下列代码:

 

三角函数的设计Sin计划

新键三个Button控件,Text属性分别 是sin、cos和tan,Name属性分别是BtSin、Btcos和Bttan。

 

三个button控件发生click事件,输入下列代码如下:

 

阶乘和10^x的功能:

新键二个Button控件,Text属性分别 是sin、cos和tan,Name属性分别是BtSin、Btcos和Bttan。

 二个button控件发生click事件,输入下列代码如下:

 平方、立方、PI、Log、ln的功能

新键五个Button控件,Text属性分别 是x^2、x^3、PI、Log和ln,Name属性分别是BtSquare、BtCube、BtPI、BtLog和Btln。

 五个button控件发生click事件,输入下列代码如下:

 

 清屏功能:

添加一个Button,Text属性是C,Name属性是BtClear。

 发生click事件,输入下列代码如下:

 Form1窗体的Text属性改为科学计算器:

 

在Form2窗体中,添加17个Button控件,其中10个数字按钮,4个运算按钮,一个用于计算的等号按钮。

10个数字按钮: 

 

在Form1里,在鼠标全部选择,按下Ctrl+V,然后在Form2,按下粘贴,整理位置。

 

从Form1的部分代码复制到Form2,结果运行不行了。只能发生click事件操作,然后从Formr的部分代码复制到Form2,才能实现同样的功能。

Form2窗体的Text属性改为普通计算器:

 

 

Form1.cs的完整代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Calculator
{
    public partial class Form1 : Form
    {
        private string Op;
        private double Op1;
        private double Op2;
        private double result;
        public Form1()
        {
            InitializeComponent();
        }

        private void 机型转换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 stu=new Form2();
            this.Hide();
            stu.ShowDialog();
            this.Close();
        }

        private void BtNumber1_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "1";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "2";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber3_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "3";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber4_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "4";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber5_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "5";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber6_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "6";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber7_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "7";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber8_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "8";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber9_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "9";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber0_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "0";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtComma_Click(object sender, EventArgs e)
        {
            if(textBox1.Text.IndexOf(".")<0)
                textBox1.Text+=((Button)sender).Text;
            else
            { }
        }

        private void BtDebgyu_Click(object sender, EventArgs e)
        {
            switch(Op)
            {
                case "+":
                    result = Op2 + Op1;
                    break;
                case "-":
                    result = Op2 - Op1;
                    break;
                case "*":
                    result = Op2 * Op1;
                    break;
                case "/":
                    if(Op2==0)
                    {
                        Console.WriteLine("错误,被除数不能为0!");
                    }
                    else
                    {
                        result= Op2/ Op1;
                    }
                    break;
                case "%":
                    result = Op2 % Op1;
                    break;
                case "^":
                    int m;double n;
                    m = 1;n = Op2;
                    while(m+1<=Op1)
                    {
                        n = n * Op2;
                        m++;
                    }
                    result = n;
                    break;
            }
            textBox1.Text = System.Convert.ToString(result);
        }

        private void BtAdd_Click(object sender, EventArgs e)
        {
            Op = "+";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtSubtract_Click(object sender, EventArgs e)
        {
            Op = "-";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtMult_Click(object sender, EventArgs e)
        {
            Op = "*";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtDivision_Click(object sender, EventArgs e)
        {
            Op = "/";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtRemedial_Click(object sender, EventArgs e)
        {
            Op = "%";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtPower_Click(object sender, EventArgs e)
        {
            Op = "^";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtDel_Click(object sender, EventArgs e)
        {
            if(textBox1.Text.Length>=1)
            {
                textBox1.Text=textBox1.Text.Substring(0,textBox1.Text.Length-1);
            }
            if(textBox1.Text.Length==0)
            {
                textBox1.Text = "";
            }
        }

        private void Btsin_Click(object sender, EventArgs e)
        {
            Convert.ToDouble(Op1);
            textBox1.Text = System.Convert.ToString(Math.Sin(Op1 * Math.PI / 180));
        }

        private void Btcos_Click(object sender, EventArgs e)
        {
            Convert.ToDouble(Op1);
            textBox1.Text = System.Convert.ToString(Math.Cos(Op1 * Math.PI / 180));
        }

        private void Bttan_Click(object sender, EventArgs e)
        {
            Convert.ToDouble(Op1);
            textBox1.Text = System.Convert.ToString(Math.Tan(Op1 * Math.PI / 180));
        }

        private void BtFactorial_Click(object sender, EventArgs e)
        {
            int i, j;
            i = 1;j = 1;
            while(i<=Op1)
            {
                j *= i;
                i++;
            }
            textBox1.Text = System.Convert.ToString(j);
        }

        private void BtIndex_Click(object sender, EventArgs e)
        {
            int a, b;
            a = 1; b = 1;
            while (a <= Op1)
            {
                b *= 10;
                a++;
            }
            textBox1.Text = System.Convert.ToString(b);
        }

        private void BtSquare_Click(object sender, EventArgs e)
        {
            textBox1.Text = System.Convert.ToString(Op1 * Op1);
        }

        private void BtCube_Click(object sender, EventArgs e)
        {
            textBox1.Text = System.Convert.ToString(Op1 * Op1 * Op1);
        }

        private void BtPI_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + Math.PI;
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtLog_Click(object sender, EventArgs e)
        {
            textBox1.Text = System.Convert.ToString(Math.Log10(Op1));
        }

        private void BtIn_Click(object sender, EventArgs e)
        {
            textBox1.Text = System.Convert.ToString(Math.Log(Op1));
        }

        private void BtClear_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            Op = "";
            Op1 = 0;
            Op2 = 0;
            result = 0;
        }
    }
}

Form1.Designer.cs的完整代码:

namespace Calculator
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要修改
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.机型转换ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.BtNumber1 = new System.Windows.Forms.Button();
            this.BtNumber2 = new System.Windows.Forms.Button();
            this.BtNumber3 = new System.Windows.Forms.Button();
            this.BtNumber4 = new System.Windows.Forms.Button();
            this.BtNumber5 = new System.Windows.Forms.Button();
            this.BtNumber6 = new System.Windows.Forms.Button();
            this.BtNumber7 = new System.Windows.Forms.Button();
            this.BtNumber8 = new System.Windows.Forms.Button();
            this.BtNumber9 = new System.Windows.Forms.Button();
            this.BtNumber0 = new System.Windows.Forms.Button();
            this.BtComma = new System.Windows.Forms.Button();
            this.BtDebgyu = new System.Windows.Forms.Button();
            this.BtAdd = new System.Windows.Forms.Button();
            this.BtSubtract = new System.Windows.Forms.Button();
            this.BtMult = new System.Windows.Forms.Button();
            this.BtDivision = new System.Windows.Forms.Button();
            this.BtRemedial = new System.Windows.Forms.Button();
            this.BtPower = new System.Windows.Forms.Button();
            this.BtDel = new System.Windows.Forms.Button();
            this.Btsin = new System.Windows.Forms.Button();
            this.Btcos = new System.Windows.Forms.Button();
            this.Bttan = new System.Windows.Forms.Button();
            this.BtFactorial = new System.Windows.Forms.Button();
            this.BtIndex = new System.Windows.Forms.Button();
            this.BtSquare = new System.Windows.Forms.Button();
            this.BtCube = new System.Windows.Forms.Button();
            this.BtPI = new System.Windows.Forms.Button();
            this.BtLog = new System.Windows.Forms.Button();
            this.BtIn = new System.Windows.Forms.Button();
            this.BtClear = new System.Windows.Forms.Button();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.GripMargin = new System.Windows.Forms.Padding(2, 2, 0, 2);
            this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.机型转换ToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(726, 32);
            this.menuStrip1.TabIndex = 0;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // 机型转换ToolStripMenuItem
            // 
            this.机型转换ToolStripMenuItem.Name = "机型转换ToolStripMenuItem";
            this.机型转换ToolStripMenuItem.Size = new System.Drawing.Size(98, 28);
            this.机型转换ToolStripMenuItem.Text = "机型转换";
            this.机型转换ToolStripMenuItem.Click += new System.EventHandler(this.机型转换ToolStripMenuItem_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(27, 53);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(659, 26);
            this.textBox1.TabIndex = 1;
            // 
            // BtNumber1
            // 
            this.BtNumber1.Location = new System.Drawing.Point(27, 163);
            this.BtNumber1.Name = "BtNumber1";
            this.BtNumber1.Size = new System.Drawing.Size(66, 46);
            this.BtNumber1.TabIndex = 2;
            this.BtNumber1.Text = "1";
            this.BtNumber1.UseVisualStyleBackColor = true;
            this.BtNumber1.Click += new System.EventHandler(this.BtNumber1_Click);
            // 
            // BtNumber2
            // 
            this.BtNumber2.Location = new System.Drawing.Point(130, 163);
            this.BtNumber2.Name = "BtNumber2";
            this.BtNumber2.Size = new System.Drawing.Size(66, 46);
            this.BtNumber2.TabIndex = 3;
            this.BtNumber2.Text = "2";
            this.BtNumber2.UseVisualStyleBackColor = true;
            this.BtNumber2.Click += new System.EventHandler(this.BtNumber2_Click);
            // 
            // BtNumber3
            // 
            this.BtNumber3.Location = new System.Drawing.Point(237, 163);
            this.BtNumber3.Name = "BtNumber3";
            this.BtNumber3.Size = new System.Drawing.Size(66, 46);
            this.BtNumber3.TabIndex = 4;
            this.BtNumber3.Text = "3";
            this.BtNumber3.UseVisualStyleBackColor = true;
            this.BtNumber3.Click += new System.EventHandler(this.BtNumber3_Click);
            // 
            // BtNumber4
            // 
            this.BtNumber4.Location = new System.Drawing.Point(27, 236);
            this.BtNumber4.Name = "BtNumber4";
            this.BtNumber4.Size = new System.Drawing.Size(66, 46);
            this.BtNumber4.TabIndex = 5;
            this.BtNumber4.Text = "4";
            this.BtNumber4.UseVisualStyleBackColor = true;
            this.BtNumber4.Click += new System.EventHandler(this.BtNumber4_Click);
            // 
            // BtNumber5
            // 
            this.BtNumber5.Location = new System.Drawing.Point(130, 236);
            this.BtNumber5.Name = "BtNumber5";
            this.BtNumber5.Size = new System.Drawing.Size(66, 46);
            this.BtNumber5.TabIndex = 6;
            this.BtNumber5.Text = "5";
            this.BtNumber5.UseVisualStyleBackColor = true;
            this.BtNumber5.Click += new System.EventHandler(this.BtNumber5_Click);
            // 
            // BtNumber6
            // 
            this.BtNumber6.Location = new System.Drawing.Point(237, 237);
            this.BtNumber6.Name = "BtNumber6";
            this.BtNumber6.Size = new System.Drawing.Size(66, 45);
            this.BtNumber6.TabIndex = 7;
            this.BtNumber6.Text = "6";
            this.BtNumber6.UseVisualStyleBackColor = true;
            this.BtNumber6.Click += new System.EventHandler(this.BtNumber6_Click);
            // 
            // BtNumber7
            // 
            this.BtNumber7.Location = new System.Drawing.Point(27, 304);
            this.BtNumber7.Name = "BtNumber7";
            this.BtNumber7.Size = new System.Drawing.Size(66, 46);
            this.BtNumber7.TabIndex = 8;
            this.BtNumber7.Text = "7";
            this.BtNumber7.UseVisualStyleBackColor = true;
            this.BtNumber7.Click += new System.EventHandler(this.BtNumber7_Click);
            // 
            // BtNumber8
            // 
            this.BtNumber8.Location = new System.Drawing.Point(130, 307);
            this.BtNumber8.Name = "BtNumber8";
            this.BtNumber8.Size = new System.Drawing.Size(66, 46);
            this.BtNumber8.TabIndex = 9;
            this.BtNumber8.Text = "8";
            this.BtNumber8.UseVisualStyleBackColor = true;
            this.BtNumber8.Click += new System.EventHandler(this.BtNumber8_Click);
            // 
            // BtNumber9
            // 
            this.BtNumber9.Location = new System.Drawing.Point(237, 304);
            this.BtNumber9.Name = "BtNumber9";
            this.BtNumber9.Size = new System.Drawing.Size(66, 49);
            this.BtNumber9.TabIndex = 10;
            this.BtNumber9.Text = "9";
            this.BtNumber9.UseVisualStyleBackColor = true;
            this.BtNumber9.Click += new System.EventHandler(this.BtNumber9_Click);
            // 
            // BtNumber0
            // 
            this.BtNumber0.Location = new System.Drawing.Point(27, 370);
            this.BtNumber0.Name = "BtNumber0";
            this.BtNumber0.Size = new System.Drawing.Size(66, 46);
            this.BtNumber0.TabIndex = 11;
            this.BtNumber0.Text = "0";
            this.BtNumber0.UseVisualStyleBackColor = true;
            this.BtNumber0.Click += new System.EventHandler(this.BtNumber0_Click);
            // 
            // BtComma
            // 
            this.BtComma.Location = new System.Drawing.Point(130, 370);
            this.BtComma.Name = "BtComma";
            this.BtComma.Size = new System.Drawing.Size(66, 46);
            this.BtComma.TabIndex = 12;
            this.BtComma.Text = ".";
            this.BtComma.UseVisualStyleBackColor = true;
            this.BtComma.Click += new System.EventHandler(this.BtComma_Click);
            // 
            // BtDebgyu
            // 
            this.BtDebgyu.Location = new System.Drawing.Point(237, 370);
            this.BtDebgyu.Name = "BtDebgyu";
            this.BtDebgyu.Size = new System.Drawing.Size(66, 46);
            this.BtDebgyu.TabIndex = 13;
            this.BtDebgyu.Text = "=";
            this.BtDebgyu.UseVisualStyleBackColor = true;
            this.BtDebgyu.Click += new System.EventHandler(this.BtDebgyu_Click);
            // 
            // BtAdd
            // 
            this.BtAdd.Location = new System.Drawing.Point(419, 163);
            this.BtAdd.Name = "BtAdd";
            this.BtAdd.Size = new System.Drawing.Size(66, 46);
            this.BtAdd.TabIndex = 14;
            this.BtAdd.Text = "+";
            this.BtAdd.UseVisualStyleBackColor = true;
            this.BtAdd.Click += new System.EventHandler(this.BtAdd_Click);
            // 
            // BtSubtract
            // 
            this.BtSubtract.Location = new System.Drawing.Point(419, 237);
            this.BtSubtract.Name = "BtSubtract";
            this.BtSubtract.Size = new System.Drawing.Size(66, 45);
            this.BtSubtract.TabIndex = 15;
            this.BtSubtract.Text = "-";
            this.BtSubtract.UseVisualStyleBackColor = true;
            this.BtSubtract.Click += new System.EventHandler(this.BtSubtract_Click);
            // 
            // BtMult
            // 
            this.BtMult.Location = new System.Drawing.Point(419, 307);
            this.BtMult.Name = "BtMult";
            this.BtMult.Size = new System.Drawing.Size(66, 49);
            this.BtMult.TabIndex = 16;
            this.BtMult.Text = "*";
            this.BtMult.UseVisualStyleBackColor = true;
            this.BtMult.Click += new System.EventHandler(this.BtMult_Click);
            // 
            // BtDivision
            // 
            this.BtDivision.Location = new System.Drawing.Point(419, 370);
            this.BtDivision.Name = "BtDivision";
            this.BtDivision.Size = new System.Drawing.Size(66, 46);
            this.BtDivision.TabIndex = 17;
            this.BtDivision.Text = "/";
            this.BtDivision.UseVisualStyleBackColor = true;
            this.BtDivision.Click += new System.EventHandler(this.BtDivision_Click);
            // 
            // BtRemedial
            // 
            this.BtRemedial.Location = new System.Drawing.Point(620, 237);
            this.BtRemedial.Name = "BtRemedial";
            this.BtRemedial.Size = new System.Drawing.Size(66, 45);
            this.BtRemedial.TabIndex = 18;
            this.BtRemedial.Text = "%";
            this.BtRemedial.UseVisualStyleBackColor = true;
            this.BtRemedial.Click += new System.EventHandler(this.BtRemedial_Click);
            // 
            // BtPower
            // 
            this.BtPower.Location = new System.Drawing.Point(330, 99);
            this.BtPower.Name = "BtPower";
            this.BtPower.Size = new System.Drawing.Size(61, 46);
            this.BtPower.TabIndex = 19;
            this.BtPower.Text = "x^y";
            this.BtPower.UseVisualStyleBackColor = true;
            this.BtPower.Click += new System.EventHandler(this.BtPower_Click);
            // 
            // BtDel
            // 
            this.BtDel.Location = new System.Drawing.Point(521, 163);
            this.BtDel.Name = "BtDel";
            this.BtDel.Size = new System.Drawing.Size(66, 46);
            this.BtDel.TabIndex = 20;
            this.BtDel.Text = "Del";
            this.BtDel.UseVisualStyleBackColor = true;
            this.BtDel.Click += new System.EventHandler(this.BtDel_Click);
            // 
            // Btsin
            // 
            this.Btsin.Location = new System.Drawing.Point(27, 99);
            this.Btsin.Name = "Btsin";
            this.Btsin.Size = new System.Drawing.Size(66, 46);
            this.Btsin.TabIndex = 21;
            this.Btsin.Text = "sin";
            this.Btsin.UseVisualStyleBackColor = true;
            this.Btsin.Click += new System.EventHandler(this.Btsin_Click);
            // 
            // Btcos
            // 
            this.Btcos.Location = new System.Drawing.Point(130, 99);
            this.Btcos.Name = "Btcos";
            this.Btcos.Size = new System.Drawing.Size(66, 46);
            this.Btcos.TabIndex = 22;
            this.Btcos.Text = "cos";
            this.Btcos.UseVisualStyleBackColor = true;
            this.Btcos.Click += new System.EventHandler(this.Btcos_Click);
            // 
            // Bttan
            // 
            this.Bttan.Location = new System.Drawing.Point(237, 99);
            this.Bttan.Name = "Bttan";
            this.Bttan.Size = new System.Drawing.Size(66, 46);
            this.Bttan.TabIndex = 23;
            this.Bttan.Text = "tan";
            this.Bttan.UseVisualStyleBackColor = true;
            this.Bttan.Click += new System.EventHandler(this.Bttan_Click);
            // 
            // BtFactorial
            // 
            this.BtFactorial.Location = new System.Drawing.Point(620, 99);
            this.BtFactorial.Name = "BtFactorial";
            this.BtFactorial.Size = new System.Drawing.Size(66, 46);
            this.BtFactorial.TabIndex = 24;
            this.BtFactorial.Text = "n!";
            this.BtFactorial.UseVisualStyleBackColor = true;
            this.BtFactorial.Click += new System.EventHandler(this.BtFactorial_Click);
            // 
            // BtIndex
            // 
            this.BtIndex.Location = new System.Drawing.Point(521, 370);
            this.BtIndex.Name = "BtIndex";
            this.BtIndex.Size = new System.Drawing.Size(165, 46);
            this.BtIndex.TabIndex = 25;
            this.BtIndex.Text = "10^x";
            this.BtIndex.UseVisualStyleBackColor = true;
            this.BtIndex.Click += new System.EventHandler(this.BtIndex_Click);
            // 
            // BtSquare
            // 
            this.BtSquare.Location = new System.Drawing.Point(521, 307);
            this.BtSquare.Name = "BtSquare";
            this.BtSquare.Size = new System.Drawing.Size(66, 43);
            this.BtSquare.TabIndex = 26;
            this.BtSquare.Text = "x^2";
            this.BtSquare.UseVisualStyleBackColor = true;
            this.BtSquare.Click += new System.EventHandler(this.BtSquare_Click);
            // 
            // BtCube
            // 
            this.BtCube.Location = new System.Drawing.Point(620, 307);
            this.BtCube.Name = "BtCube";
            this.BtCube.Size = new System.Drawing.Size(66, 45);
            this.BtCube.TabIndex = 27;
            this.BtCube.Text = "x^3";
            this.BtCube.UseVisualStyleBackColor = true;
            this.BtCube.Click += new System.EventHandler(this.BtCube_Click);
            // 
            // BtPI
            // 
            this.BtPI.Location = new System.Drawing.Point(521, 237);
            this.BtPI.Name = "BtPI";
            this.BtPI.Size = new System.Drawing.Size(66, 45);
            this.BtPI.TabIndex = 28;
            this.BtPI.Text = "PI";
            this.BtPI.UseVisualStyleBackColor = true;
            this.BtPI.Click += new System.EventHandler(this.BtPI_Click);
            // 
            // BtLog
            // 
            this.BtLog.Location = new System.Drawing.Point(419, 99);
            this.BtLog.Name = "BtLog";
            this.BtLog.Size = new System.Drawing.Size(66, 46);
            this.BtLog.TabIndex = 29;
            this.BtLog.Text = " Log";
            this.BtLog.UseVisualStyleBackColor = true;
            this.BtLog.Click += new System.EventHandler(this.BtLog_Click);
            // 
            // BtIn
            // 
            this.BtIn.Location = new System.Drawing.Point(521, 99);
            this.BtIn.Name = "BtIn";
            this.BtIn.Size = new System.Drawing.Size(66, 46);
            this.BtIn.TabIndex = 30;
            this.BtIn.Text = "ln";
            this.BtIn.UseVisualStyleBackColor = true;
            this.BtIn.Click += new System.EventHandler(this.BtIn_Click);
            // 
            // BtClear
            // 
            this.BtClear.Location = new System.Drawing.Point(620, 163);
            this.BtClear.Name = "BtClear";
            this.BtClear.Size = new System.Drawing.Size(66, 46);
            this.BtClear.TabIndex = 31;
            this.BtClear.Text = "C";
            this.BtClear.UseVisualStyleBackColor = true;
            this.BtClear.Click += new System.EventHandler(this.BtClear_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(726, 450);
            this.Controls.Add(this.BtClear);
            this.Controls.Add(this.BtIn);
            this.Controls.Add(this.BtLog);
            this.Controls.Add(this.BtPI);
            this.Controls.Add(this.BtCube);
            this.Controls.Add(this.BtSquare);
            this.Controls.Add(this.BtIndex);
            this.Controls.Add(this.BtFactorial);
            this.Controls.Add(this.Bttan);
            this.Controls.Add(this.Btcos);
            this.Controls.Add(this.Btsin);
            this.Controls.Add(this.BtDel);
            this.Controls.Add(this.BtPower);
            this.Controls.Add(this.BtRemedial);
            this.Controls.Add(this.BtDivision);
            this.Controls.Add(this.BtMult);
            this.Controls.Add(this.BtSubtract);
            this.Controls.Add(this.BtAdd);
            this.Controls.Add(this.BtDebgyu);
            this.Controls.Add(this.BtComma);
            this.Controls.Add(this.BtNumber0);
            this.Controls.Add(this.BtNumber9);
            this.Controls.Add(this.BtNumber8);
            this.Controls.Add(this.BtNumber7);
            this.Controls.Add(this.BtNumber6);
            this.Controls.Add(this.BtNumber5);
            this.Controls.Add(this.BtNumber4);
            this.Controls.Add(this.BtNumber3);
            this.Controls.Add(this.BtNumber2);
            this.Controls.Add(this.BtNumber1);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "科学计算器";
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem 机型转换ToolStripMenuItem;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button BtNumber1;
        private System.Windows.Forms.Button BtNumber2;
        private System.Windows.Forms.Button BtNumber3;
        private System.Windows.Forms.Button BtNumber4;
        private System.Windows.Forms.Button BtNumber5;
        private System.Windows.Forms.Button BtNumber6;
        private System.Windows.Forms.Button BtNumber7;
        private System.Windows.Forms.Button BtNumber8;
        private System.Windows.Forms.Button BtNumber9;
        private System.Windows.Forms.Button BtNumber0;
        private System.Windows.Forms.Button BtComma;
        private System.Windows.Forms.Button BtDebgyu;
        private System.Windows.Forms.Button BtAdd;
        private System.Windows.Forms.Button BtSubtract;
        private System.Windows.Forms.Button BtMult;
        private System.Windows.Forms.Button BtDivision;
        private System.Windows.Forms.Button BtRemedial;
        private System.Windows.Forms.Button BtPower;
        private System.Windows.Forms.Button BtDel;
        private System.Windows.Forms.Button Btsin;
        private System.Windows.Forms.Button Btcos;
        private System.Windows.Forms.Button Bttan;
        private System.Windows.Forms.Button BtFactorial;
        private System.Windows.Forms.Button BtIndex;
        private System.Windows.Forms.Button BtSquare;
        private System.Windows.Forms.Button BtCube;
        private System.Windows.Forms.Button BtPI;
        private System.Windows.Forms.Button BtLog;
        private System.Windows.Forms.Button BtIn;
        private System.Windows.Forms.Button BtClear;
    }
}

Form2.cs的完整代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Calculator
{
    public partial class Form2 : Form
    {
        private string Op;
        private double Op1;
        private double Op2;
        private double result;
        public Form2()
        {
            InitializeComponent();
        }

        private void 机型转换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 stu=new Form1();
            this.Hide();
            stu.ShowDialog();
            this.Close();
        }

        private void BtNumber1_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "1";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "2";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber3_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "3";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber4_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "4";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber5_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "5";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber6_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "6";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber7_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "7";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber8_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "8";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber9_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "9";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtNumber0_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "0";
            Op1 = System.Convert.ToDouble(textBox1.Text);
        }

        private void BtComma_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.IndexOf(".") < 0)
                textBox1.Text += ((Button)sender).Text;
            else
            { }
        }

        private void BtDebgyu_Click(object sender, EventArgs e)
        {
            switch (Op)
            {
                case "+":
                    result = Op2 + Op1;
                    break;
                case "-":
                    result = Op2 - Op1;
                    break;
                case "*":
                    result = Op2 * Op1;
                    break;
                case "/":
                    if (Op2 == 0)
                    {
                        Console.WriteLine("错误,被除数不能为0!");
                    }
                    else
                    {
                        result = Op2 / Op1;
                    }
                    break;
                case "%":
                    result = Op2 % Op1;
                    break;
                case "^":
                    int m; double n;
                    m = 1; n = Op2;
                    while (m + 1 <= Op1)
                    {
                        n = n * Op2;
                        m++;
                    }
                    result = n;
                    break;
            }
            textBox1.Text = System.Convert.ToString(result);
        }

        private void BtAdd_Click(object sender, EventArgs e)
        {
            Op = "+";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtSubtract_Click(object sender, EventArgs e)
        {
            Op = "-";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtMult_Click(object sender, EventArgs e)
        {
            Op = "*";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtDivision_Click(object sender, EventArgs e)
        {
            Op = "/";
            Op2 = Op1;
            textBox1.Text = "";
        }

        private void BtClear_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            Op = "";
            Op1 = 0;
            Op2 = 0;
            result = 0;
        }
    }
}

Form2.Designer.cs的完整代码:

namespace Calculator
{
    partial class Form2
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.机型转换ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.BtClear = new System.Windows.Forms.Button();
            this.BtDivision = new System.Windows.Forms.Button();
            this.BtMult = new System.Windows.Forms.Button();
            this.BtSubtract = new System.Windows.Forms.Button();
            this.BtAdd = new System.Windows.Forms.Button();
            this.BtDebgyu = new System.Windows.Forms.Button();
            this.BtComma = new System.Windows.Forms.Button();
            this.BtNumber0 = new System.Windows.Forms.Button();
            this.BtNumber9 = new System.Windows.Forms.Button();
            this.BtNumber8 = new System.Windows.Forms.Button();
            this.BtNumber7 = new System.Windows.Forms.Button();
            this.BtNumber6 = new System.Windows.Forms.Button();
            this.BtNumber5 = new System.Windows.Forms.Button();
            this.BtNumber4 = new System.Windows.Forms.Button();
            this.BtNumber3 = new System.Windows.Forms.Button();
            this.BtNumber2 = new System.Windows.Forms.Button();
            this.BtNumber1 = new System.Windows.Forms.Button();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.GripMargin = new System.Windows.Forms.Padding(2, 2, 0, 2);
            this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.机型转换ToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(432, 32);
            this.menuStrip1.TabIndex = 0;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // 机型转换ToolStripMenuItem
            // 
            this.机型转换ToolStripMenuItem.Name = "机型转换ToolStripMenuItem";
            this.机型转换ToolStripMenuItem.Size = new System.Drawing.Size(98, 28);
            this.机型转换ToolStripMenuItem.Text = "机型转换";
            this.机型转换ToolStripMenuItem.Click += new System.EventHandler(this.机型转换ToolStripMenuItem_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(12, 50);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(387, 26);
            this.textBox1.TabIndex = 1;
            // 
            // BtClear
            // 
            this.BtClear.Location = new System.Drawing.Point(232, 94);
            this.BtClear.Name = "BtClear";
            this.BtClear.Size = new System.Drawing.Size(167, 46);
            this.BtClear.TabIndex = 48;
            this.BtClear.Text = "C";
            this.BtClear.UseVisualStyleBackColor = true;
            this.BtClear.Click += new System.EventHandler(this.BtClear_Click);
            // 
            // BtDivision
            // 
            this.BtDivision.Location = new System.Drawing.Point(333, 373);
            this.BtDivision.Name = "BtDivision";
            this.BtDivision.Size = new System.Drawing.Size(66, 46);
            this.BtDivision.TabIndex = 47;
            this.BtDivision.Text = "/";
            this.BtDivision.UseVisualStyleBackColor = true;
            this.BtDivision.Click += new System.EventHandler(this.BtDivision_Click);
            // 
            // BtMult
            // 
            this.BtMult.Location = new System.Drawing.Point(333, 310);
            this.BtMult.Name = "BtMult";
            this.BtMult.Size = new System.Drawing.Size(66, 49);
            this.BtMult.TabIndex = 46;
            this.BtMult.Text = "*";
            this.BtMult.UseVisualStyleBackColor = true;
            this.BtMult.Click += new System.EventHandler(this.BtMult_Click);
            // 
            // BtSubtract
            // 
            this.BtSubtract.Location = new System.Drawing.Point(333, 240);
            this.BtSubtract.Name = "BtSubtract";
            this.BtSubtract.Size = new System.Drawing.Size(66, 45);
            this.BtSubtract.TabIndex = 45;
            this.BtSubtract.Text = "-";
            this.BtSubtract.UseVisualStyleBackColor = true;
            this.BtSubtract.Click += new System.EventHandler(this.BtSubtract_Click);
            // 
            // BtAdd
            // 
            this.BtAdd.Location = new System.Drawing.Point(333, 166);
            this.BtAdd.Name = "BtAdd";
            this.BtAdd.Size = new System.Drawing.Size(66, 46);
            this.BtAdd.TabIndex = 44;
            this.BtAdd.Text = "+";
            this.BtAdd.UseVisualStyleBackColor = true;
            this.BtAdd.Click += new System.EventHandler(this.BtAdd_Click);
            // 
            // BtDebgyu
            // 
            this.BtDebgyu.Location = new System.Drawing.Point(232, 373);
            this.BtDebgyu.Name = "BtDebgyu";
            this.BtDebgyu.Size = new System.Drawing.Size(66, 46);
            this.BtDebgyu.TabIndex = 43;
            this.BtDebgyu.Text = "=";
            this.BtDebgyu.UseVisualStyleBackColor = true;
            this.BtDebgyu.Click += new System.EventHandler(this.BtDebgyu_Click);
            // 
            // BtComma
            // 
            this.BtComma.Location = new System.Drawing.Point(125, 373);
            this.BtComma.Name = "BtComma";
            this.BtComma.Size = new System.Drawing.Size(66, 46);
            this.BtComma.TabIndex = 42;
            this.BtComma.Text = ".";
            this.BtComma.UseVisualStyleBackColor = true;
            this.BtComma.Click += new System.EventHandler(this.BtComma_Click);
            // 
            // BtNumber0
            // 
            this.BtNumber0.Location = new System.Drawing.Point(22, 373);
            this.BtNumber0.Name = "BtNumber0";
            this.BtNumber0.Size = new System.Drawing.Size(66, 46);
            this.BtNumber0.TabIndex = 41;
            this.BtNumber0.Text = "0";
            this.BtNumber0.UseVisualStyleBackColor = true;
            this.BtNumber0.Click += new System.EventHandler(this.BtNumber0_Click);
            // 
            // BtNumber9
            // 
            this.BtNumber9.Location = new System.Drawing.Point(232, 307);
            this.BtNumber9.Name = "BtNumber9";
            this.BtNumber9.Size = new System.Drawing.Size(66, 49);
            this.BtNumber9.TabIndex = 40;
            this.BtNumber9.Text = "9";
            this.BtNumber9.UseVisualStyleBackColor = true;
            this.BtNumber9.Click += new System.EventHandler(this.BtNumber9_Click);
            // 
            // BtNumber8
            // 
            this.BtNumber8.Location = new System.Drawing.Point(125, 310);
            this.BtNumber8.Name = "BtNumber8";
            this.BtNumber8.Size = new System.Drawing.Size(66, 46);
            this.BtNumber8.TabIndex = 39;
            this.BtNumber8.Text = "8";
            this.BtNumber8.UseVisualStyleBackColor = true;
            this.BtNumber8.Click += new System.EventHandler(this.BtNumber8_Click);
            // 
            // BtNumber7
            // 
            this.BtNumber7.Location = new System.Drawing.Point(22, 307);
            this.BtNumber7.Name = "BtNumber7";
            this.BtNumber7.Size = new System.Drawing.Size(66, 46);
            this.BtNumber7.TabIndex = 38;
            this.BtNumber7.Text = "7";
            this.BtNumber7.UseVisualStyleBackColor = true;
            this.BtNumber7.Click += new System.EventHandler(this.BtNumber7_Click);
            // 
            // BtNumber6
            // 
            this.BtNumber6.Location = new System.Drawing.Point(232, 240);
            this.BtNumber6.Name = "BtNumber6";
            this.BtNumber6.Size = new System.Drawing.Size(66, 45);
            this.BtNumber6.TabIndex = 37;
            this.BtNumber6.Text = "6";
            this.BtNumber6.UseVisualStyleBackColor = true;
            this.BtNumber6.Click += new System.EventHandler(this.BtNumber6_Click);
            // 
            // BtNumber5
            // 
            this.BtNumber5.Location = new System.Drawing.Point(125, 239);
            this.BtNumber5.Name = "BtNumber5";
            this.BtNumber5.Size = new System.Drawing.Size(66, 46);
            this.BtNumber5.TabIndex = 36;
            this.BtNumber5.Text = "5";
            this.BtNumber5.UseVisualStyleBackColor = true;
            this.BtNumber5.Click += new System.EventHandler(this.BtNumber5_Click);
            // 
            // BtNumber4
            // 
            this.BtNumber4.Location = new System.Drawing.Point(22, 239);
            this.BtNumber4.Name = "BtNumber4";
            this.BtNumber4.Size = new System.Drawing.Size(66, 46);
            this.BtNumber4.TabIndex = 35;
            this.BtNumber4.Text = "4";
            this.BtNumber4.UseVisualStyleBackColor = true;
            this.BtNumber4.Click += new System.EventHandler(this.BtNumber4_Click);
            // 
            // BtNumber3
            // 
            this.BtNumber3.Location = new System.Drawing.Point(232, 166);
            this.BtNumber3.Name = "BtNumber3";
            this.BtNumber3.Size = new System.Drawing.Size(66, 46);
            this.BtNumber3.TabIndex = 34;
            this.BtNumber3.Text = "3";
            this.BtNumber3.UseVisualStyleBackColor = true;
            this.BtNumber3.Click += new System.EventHandler(this.BtNumber3_Click);
            // 
            // BtNumber2
            // 
            this.BtNumber2.Location = new System.Drawing.Point(125, 166);
            this.BtNumber2.Name = "BtNumber2";
            this.BtNumber2.Size = new System.Drawing.Size(66, 46);
            this.BtNumber2.TabIndex = 33;
            this.BtNumber2.Text = "2";
            this.BtNumber2.UseVisualStyleBackColor = true;
            this.BtNumber2.Click += new System.EventHandler(this.BtNumber2_Click);
            // 
            // BtNumber1
            // 
            this.BtNumber1.Location = new System.Drawing.Point(22, 166);
            this.BtNumber1.Name = "BtNumber1";
            this.BtNumber1.Size = new System.Drawing.Size(66, 46);
            this.BtNumber1.TabIndex = 32;
            this.BtNumber1.Text = "1";
            this.BtNumber1.UseVisualStyleBackColor = true;
            this.BtNumber1.Click += new System.EventHandler(this.BtNumber1_Click);
            // 
            // Form2
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(432, 450);
            this.Controls.Add(this.BtClear);
            this.Controls.Add(this.BtDivision);
            this.Controls.Add(this.BtMult);
            this.Controls.Add(this.BtSubtract);
            this.Controls.Add(this.BtAdd);
            this.Controls.Add(this.BtDebgyu);
            this.Controls.Add(this.BtComma);
            this.Controls.Add(this.BtNumber0);
            this.Controls.Add(this.BtNumber9);
            this.Controls.Add(this.BtNumber8);
            this.Controls.Add(this.BtNumber7);
            this.Controls.Add(this.BtNumber6);
            this.Controls.Add(this.BtNumber5);
            this.Controls.Add(this.BtNumber4);
            this.Controls.Add(this.BtNumber3);
            this.Controls.Add(this.BtNumber2);
            this.Controls.Add(this.BtNumber1);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form2";
            this.Text = "普通计算器";
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem 机型转换ToolStripMenuItem;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button BtClear;
        private System.Windows.Forms.Button BtDivision;
        private System.Windows.Forms.Button BtMult;
        private System.Windows.Forms.Button BtSubtract;
        private System.Windows.Forms.Button BtAdd;
        private System.Windows.Forms.Button BtDebgyu;
        private System.Windows.Forms.Button BtComma;
        private System.Windows.Forms.Button BtNumber0;
        private System.Windows.Forms.Button BtNumber9;
        private System.Windows.Forms.Button BtNumber8;
        private System.Windows.Forms.Button BtNumber7;
        private System.Windows.Forms.Button BtNumber6;
        private System.Windows.Forms.Button BtNumber5;
        private System.Windows.Forms.Button BtNumber4;
        private System.Windows.Forms.Button BtNumber3;
        private System.Windows.Forms.Button BtNumber2;
        private System.Windows.Forms.Button BtNumber1;
    }
}

《Visual C# 程序设计》课程学习(10)——第10章 Windows 窗体应用程序开发 10.1 Windows窗体编程基础 10.1.1 WinForms概述 #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </s... 阅读详情

相关推荐

C#编写的windows计算器-源代码

C#编写的windows计算器-源代码 [ 繁體中文 ] | 文章类别:C#应用 | 文章等级: | 发表日期:2005-6-18  星期六网站计数器 | 魔法表情申请 | 精彩博客 var arrBaiduCproConfig=new Array();arrBaiduCproConfig[uid] = 2214;arrBaiduCproConfig[n] = sayyes

在水一方 3525

C#实现简易计算器01(窗体应用)

实现页面布局和数值初始化 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsAppCal

qq_951274168的博客 870

C#实战项目1 Windows计算器的制作

文章目录系统功能描述具体实现 系统功能描述 Windows计算器是利用C#程序编写一个简易计算器程序,可以进行简单的加减乘除,还可以实现对三角函数,对数,指数等高级运算的功能。 科学计算器:包括加,减,乘,除,三角函数运算,指数运算,对数运算,幂运算,求余运算。 具体实现 private string op; private double op1; private double op2; private double result; publi

weixin_43725617的博客 775

手把手教你用C#语言写一个简单计算器窗体(附源代码文件和演示视频)

手把手教你用C#语言写一个简单计算器窗体(附源代码文件和演示视频)过程详细简单易懂!适合小白学习入门,大佬不喜勿喷!!!

xiaozhang0316的博客 2万+

C#项目实战——Windows计算器的制作【实例】

参考《C#从入门到项目实践》边学习,边练习实现。

做有价值的事,积累有价值的笔记! 1594

C#基础与Windows Forms实践:制作计算器小程序

C#(发音为 “看井”)是一种由微软开发的现代化、面向对象的编程语言。自2002年首次发布以来,C#已经成为了.NET平台上的主要语言之一,广泛应用于开发Windows桌面应用、游戏(如Unity引擎)、Web应用和云服务等。C#是一个强类型语言,这意味着每个变量都必须声明其数据类型。C#内置了多种数据类型,它们可以大致分为两类:值类型和引用类型。值类型存储实际的数据值,而引用类型则存储指向实际数据的引用。常见的值类型包括:整型(int字符型(char浮点型(float。

weixin_42515392的博客 1189

小程序制作:C# - Windows窗体应用制作加法计算器

说明 本章所讲述的所有黑客技术,均不得用于非法目的。 如果你觉得文章含有侵权部分,可以联系优快云私聊,我会适当修改。 未经允许,不得转载,如需转载,请优快云私聊。 大佬勿喷 这些小程序都是简单的小程序,所以大佬勿喷啊! 如果你喜欢这个教程的话,请点个赞吧,谢谢! 大概思路 我们要用C#做一个加法计算器,然后我们可以使用Visual Studio 2019的WIndows窗体应用来完成GUI的制作和设计。计算器的核心算法非常简单。 准备 安装Visual Studio 2019 最新版的VS IDE是非

to_run_with_wind的博客 7884

C#语言实现多功能计算器的全面指南

C#(发音为 “C sharp”)是一种由微软开发的面向对象的编程语言。作为.NET框架的核心编程语言之一,C#在2000年首次被引入,并随着每个新版本的.NET框架不断进化。它起源于C和C++语言,因此继承了C++的强大和灵活性,同时为开发者提供了简化的语法和自动内存管理(垃圾收集)特性。C#语言强调安全、现代、组件化和类型安全的设计。

weixin_29363791的博客 1085

C#之简易计算器的制作

制作一个简易的C#计算器,我们可以使用Windows Forms应用程序来实现。Windows Forms是一个用于创建图形用户界面的框架,它允许我们通过拖放控件来设计应用程序界面,并通过编写C#代码来添加逻辑。

学习和分享 1530

C#语言开发的Windows风格计算器完整教程

C#被设计为一种简单、现代、通用、面向对象的编程语言。它具有丰富、强大的表达能力,同时能够应对各种编程任务,从简单的脚本到复杂的、多层次的软件系统。科学计算器扩展功能是通过添加更多数学函数和操作来实现的,包括但不限于三角函数、对数运算、幂次方、平方根等。这些功能是许多工程、科学计算或高级数学问题所必需的。用户自定义功能让最终用户可以根据需要扩展计算器的功能。用户可以创建新的操作或修改现有操作。

weixin_35906794的博客 1029

数据结构实现计算器 (完整,代码程序)

数据结构,计算器,非常好,适合学习,进步等等!

一个枯燥无味的C#计算器-Windows计算器

首先上效果图 可能很多地方处理得并没有很好,刚上这个C#窗口课反正是一脸蒙蔽。就被布置了个写计算器的作业。可能老师对我的理解能力太自信了,我是真的写哪写什么都没搞懂,写哪会显示出什么都不知道,反正胡搞毛搞交作业。本来是不太乐意交trash的人,但这我是真没懂。 不过既然发了,那观众照着这个一定是可以做出我这图上的效果的。看别的博客真是个不断踩坑的过程。 界面控件的名称和属性设置 控件类型 控件名称Name 属性值TabIndex 备注 textbox textbox1 数字打印

ZYJ_OvO的博客 422

别再为多相机标定头疼了!用VisionMaster统一坐标系的保姆级教程

本文详细介绍了使用VisionMaster平台解决多相机视觉系统中坐标系统一问题的完整流程。从标定板选择到N点标定,再到实战演练,提供了从原理到落地的全方位指导,帮助工程师高效解决多相机定位引导中的坐标偏差问题。

weixin_38168322的博客 632

根据陈广老师的视频,做了一个俄罗斯方块

暑假在家里学习C#基础编程,边听陈广老师的视频,边学习C#基础知识。接下来准备做一下Windows中的计算器。加油!   PS:第一篇博客,居然写成了日记形式的流水账。update at 2014/3/31...

weixin_34146410的博客 181

前端零代码丨UIOTOS + NodeRed:无代码搭建工控上位机的绝配组合!

用户类型价值硬件产品商软硬一体方案,无代码GUI上位机成新卖点软件服务商售前原型演示利器,交付成本降低至1/3平台开发商融合无代码技术,同质化竞争中脱颖而出🚀 总结UIOTOS的前端零代码设计(页面嵌套、属性继承、节点连线)与NodeRed的后端流程自动化,堪称工控与IoT开发的黄金组合。无论是串口通信、SCADA监控还是业务管理,均能实现“无代码交付”,真正让前端不求人,硬件交互触手可及!探索更多案例:UIOTOS官网在线体验。

2502_91192798的博客 757

工业缺陷检测深度学习方法综述

异常:点异常、 上下文异常和集群异常。点异常:又称为离群值 (outliers)[9], 描述数值上偏离正 常样本的独立数据。与异常相近的概念还包括新颖点(novelty)和分布外数据。上下文异常:同样描述数据点,其数值属于正常范围,但不符合局部上下文规律。集群异常:描述一系列相关数据的集合,集合中的每一个实例的数值在单独考察时都处于正常值域,但集 合整体的相关性特征不服从正常模式。一般的图像异常检测往往仅需区分正常与异常样本,而工业缺陷检测更关注于检测 图像中的异常像素.

2301_80355452的博客 1842

2020-03-28

在Windows的visual studio学习了几个月C#过后,就只编了个集成计算器出来。现在买了Java的教材,感觉微软的.net战略失败了,我是否应该及时转战?

qq_45547041的博客 61

MATLAB实战:手把手教你搭建构网逆变器同步稳定性仿真模型(附避坑指南)

本文详细介绍了如何在MATLAB/Simulink平台上搭建构网逆变器同步稳定性仿真模型,涵盖从基础模块配置到虚拟同步机控制实现的完整流程。针对电力电子工程师常见的控制参数整定困难、仿真结果偏差等问题,提供了LCL滤波器谐振抑制、虚拟惯量优化等关键技术解决方案,并附有避坑指南和工程实践技巧,助力研究者高效完成仿真建模。

weixin_29051193的博客 297

软工第一次作业:制作一个简易计算器

3.接着我们对输入的按键进行判断,我主要分为五类,第一类是双操作符,例如+,-,×,÷,x^y(实现次方和幂),第二类是等于号,第三类是一些功能性按键,例如归零(CE),删除最后一个输入的数字(C)等,第四类是只需要一个数字即可完成的运算,例如sin,cos,ln,x^2等,第五类则是0,1,2,3,4,...这样的数字,然后将这些类分别用if和else if隔开进行操作。4.特别注意的是π和e虽然在数学看来是一个常数,但是不能够按照平常的数(0,1,2,...)进行处理,因此需要单独进行处理和判断。

W5217543的博客 483

《C++面向对象程序设计》✍千处细节、万字总结(建议收藏)

《C++面向对象程序设计》✍千处细节、万字总结 文章目录《C++面向对象程序设计》✍千处细节、万字总结一、面向对象程序设计二、C++基础2.1 C++的产生和特点2.2 一个简单的C++示例程序2.3 C++在非面向对象方面对C语言的扩充输入和输出cinconst修饰符void型指针内联函数带有默认参数值的函数函数重载作用域标识符"::"强制类型转换new和delete运算符引用三、类和对象(一)3.1 类的构成3.2 成员函数的定义3.3 对象的定义和使用3.4 构造函数与析构函数构造函数成员初始化列表

像写诗一样优雅地写代码~ 78万+

OData 请求里的 Nextlink 实战:在 ABAP Client Proxy 中优雅处理长列表分页

本文介绍了OData v4标准中的@odata.nextLink分页机制及其在SAP ABAP中的实践应用。重点解析了该机制通过服务端提供的完整URL实现分页获取,客户端只需循环处理直到该字段消失的特点。文章提供了清晰的ABAP代码模板,展示如何通过Remote Client Proxy实现分页数据获取,并强调了仅支持OData v4和远程消费的限制条件。通过HR员工数据聚合的实际案例,说明了流式分页处理的最佳实践,包括服务端过滤、稳定排序和内存控制等关键技术要点,为ABAP开发者提供了可直接落地的解决方案

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 269

C#窗体程序,简易计算器

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.W...

赖卓成的博客 5359

智能测试策略优化:平衡覆盖率、时间和资源

在软件开发过程中,测试是确保软件质量的关键环节。然而,测试工作往往面临着诸多挑战,其中如何在保证测试覆盖率的前提下,合理分配时间和资源是一个核心问题。本文章的目的在于探讨智能测试策略的优化方法,帮助软件测试团队在有限的时间和资源条件下,实现尽可能高的测试覆盖率。文章的范围涵盖了智能测试策略的核心概念、算法原理、数学模型、实际应用案例以及相关工具和资源等方面。本文将按照以下结构进行组织:首先介绍智能测试策略优化的背景和相关概念,包括核心术语和缩略词的定义;

AIGC应用创新大全的博客 620
上一篇: C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
下一篇: 自助取款机系统(C#)
DXB2021
博客等级 码龄5年 307粉丝 289原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值