C# 计算器

来源:互联网 发布:台州招聘淘宝美工学徒 编辑:程序博客网 时间:2024/05/24 01:47

自己写的一个超级简单的计算器程序,算是开始入门:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication2{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void btn_caculate_Click(object sender, EventArgs e)        {            //1. 获取数据            String num1 = textBox1.Text;            String num2 = textBox2.Text;            //int result = int.Parse(num1) + int.Parse(num2);            //2.类型转换            int a=int.Parse(num1);            int b=int.Parse(num2);            double result = 0;            //3.判断用户选择计算规则            if (rad_add.Checked == true)            {                result = a + b;            }            else if (rad_minus.Checked == true)            {                result = a - b;            }            else if (rad_mult.Checked == true)            {                result = a * b;            }            else if (rad_divid.Checked == true)            {                result = a / b;            }            //4.文本框显示            txt_result.Text = result.ToString();            MessageBox.Show(result.ToString());        }    }}


0 0
原创粉丝点击