最早写的C#计算器

.NET zhaosay 2193℃ 0评论

这是大学时候写的计算器,聊以慰藉曾经的青春。

C#写的计算器截图

代码如下,有需要可以参考下:

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

namespace jsq
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void 清空ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = "";
            this.comboBox1.Text = "";
            this.textBox2.Text = "";
            this.textBox3.Text = "";
            this.label1.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "" || this.textBox2.Text == "")
            {
                MessageBox.Show("你的输入有误!");
            }
            else
            {
                string i = this.comboBox1.SelectedItem.ToString();
                switch (i)
                {
                    case "+": double a = double.Parse(this.textBox1.Text);
                        double b = double.Parse(this.textBox2.Text);
                        double c = a + b;
                        this.textBox3.Text = c.ToString();
                        break;
                    case "-": a = double.Parse(this.textBox1.Text);
                        b = double.Parse(this.textBox2.Text);
                        c = a - b;
                        this.textBox3.Text = c.ToString();
                        break;
                    case "*": a = double.Parse(this.textBox1.Text);
                        b = double.Parse(this.textBox2.Text);
                        c = a * b;
                        this.textBox3.Text = c.ToString();
                        break;
                    case "/": a = double.Parse(this.textBox1.Text);
                        b = double.Parse(this.textBox2.Text);
                        c = a / b;
                        this.textBox3.Text = c.ToString();
                        break;
                }
            }
            this.label2.Text = "  " + this.textBox1.Text + this.comboBox1.Text + this.textBox2.Text + "=" + this.textBox3.Text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = "";
            this.comboBox1.Text = "";
            this.textBox2.Text = "";
            this.textBox3.Text = "";
            this.label1.Text = "";
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("               制作:黑色雪               \n\n               时间:7月24日               ");
        }
    }
}

也可以下载自己看:百度云盘链接: https://pan.baidu.com/s/13atC0Ok7VqDwhH55XBMSiw 密码: x6pu

转载请注明:三五二萌文网 » 最早写的C#计算器

喜欢 (4)

您必须 登录 才能发表评论!