欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C#简单计算器源码

程序员文章站 2022-07-16 19:02:11
...

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.Windows.Forms;

namespace 简单计算器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            //string v = this.ProductName;
            //this.UseWaitCursor = new bool();
            int num1 = Convert.ToInt32(textBox1.Text);
            int num2 = Convert.ToInt32(textBox2.Text);
            string type = comboBox1.SelectedItem.ToString();
            

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int num1 = Convert.ToInt32(textBox1.Text);
            int num2 = Convert.ToInt32(textBox2.Text);
            string type = comboBox1.SelectedItem.ToString();
            if (type=="+")
            {
                int sum = num1 + num2;
                label2.Text = Convert.ToString(sum);
            }
            if (type == "-")
            {
                int sum = num1 - num2;
                label2.Text = Convert.ToString(sum);
                
            }
            if (type == "*")
            {
                int sum = num1 * num2;
                label2.Text = Convert.ToString(sum);
                
            }
            if (type == "/")
            {
                int sum = num1 / num2;
                label2.Text = Convert.ToString(sum);
                
            }
        }
    }
}

运行结果:C#简单计算器源码