c#-编写简易计算器

c#-编写简易计算器,第1张

概述设计如图所示。相关代码如下: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 Sy...

设计如图所示。

相关代码如下:

using System;@H_403_11@using System.Collections.Generic;@H_403_11@using System.ComponentModel;@H_403_11@using System.Data;@H_403_11@using System.Drawing;@H_403_11@using System.linq;@H_403_11@using System.Text;@H_403_11@using System.Threading.Tasks;@H_403_11@using System.windows.Forms;@H_403_11@@H_403_11@@H_403_11@namespace windowsFormsApp8_计算器@H_403_11@{@H_403_11@    public partial class Form1 : Form@H_403_11@    {@H_403_11@        public double num;  //全局变量num,用于存储第一个数字@H_403_11@        public int temp = 0;  //全局变量temp,用于判断“加减乘除”@H_403_11@        public Form1()@H_403_11@        {@H_403_11@            InitializeComponent();@H_403_11@        }@H_403_11@@H_403_11@        private voID button15_Click(object sender,EventArgs e)  //“=”按钮@H_403_11@        {@H_403_11@            if (textBox1.Text == "")@H_403_11@                MessageBox.Show("请输入数据");@H_403_11@            else@H_403_11@            {@H_403_11@                switch (temp)@H_403_11@                {@H_403_11@                    case 1: textBox1.Text = (num + Convert.Todouble(textBox1.Text)).ToString(); break;@H_403_11@                    case 2: textBox1.Text = (num - Convert.Todouble(textBox1.Text)).ToString(); break;@H_403_11@                    case 3: textBox1.Text = (num * Convert.Todouble(textBox1.Text)).ToString(); break;@H_403_11@                    case 4:@H_403_11@                        if (Convert.Todouble(textBox1.Text) == 0)@H_403_11@                        {@H_403_11@                            MessageBox.Show("除数不能为0,请重新输入");@H_403_11@                            textBox1.Clear();@H_403_11@                        }@H_403_11@                        else@H_403_11@                            textBox1.Text = (num / Convert.Todouble(textBox1.Text)).ToString(); break;@H_403_11@                }@H_403_11@            }@H_403_11@        }@H_403_11@@H_403_11@        private voID button10_Click(object sender,EventArgs e)  //清0按钮@H_403_11@        {@H_403_11@            textBox1.Text = "";@H_403_11@        }@H_403_11@@H_403_11@        private voID button0_Click(object sender,EventArgs e)  //数字0按钮@H_403_11@        {@H_403_11@            textBox1.Text += 0;@H_403_11@        }@H_403_11@@H_403_11@        private voID button1_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 1;@H_403_11@        }@H_403_11@@H_403_11@        private voID button2_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 2;@H_403_11@        }@H_403_11@@H_403_11@        private voID button3_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 3;@H_403_11@        }@H_403_11@@H_403_11@        private voID button4_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 4;@H_403_11@        }@H_403_11@@H_403_11@        private voID button5_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 5;@H_403_11@        }@H_403_11@@H_403_11@        private voID button6_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 6;@H_403_11@        }@H_403_11@@H_403_11@        private voID button7_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 7;@H_403_11@        }@H_403_11@@H_403_11@        private voID button8_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 8;@H_403_11@        }@H_403_11@@H_403_11@        private voID button9_Click(object sender,EventArgs e)@H_403_11@        {@H_403_11@            textBox1.Text += 9;@H_403_11@        }@H_403_11@@H_403_11@        private voID button11_Click(object sender,EventArgs e)  //“加”按钮@H_403_11@        {@H_403_11@            temp = 1;@H_403_11@            num = Convert.Todouble(textBox1.Text);@H_403_11@            textBox1.Text = "";@H_403_11@        }@H_403_11@@H_403_11@        private voID button12_Click(object sender,EventArgs e)  //“减”按钮@H_403_11@        {@H_403_11@            temp = 2;@H_403_11@            num = Convert.Todouble(textBox1.Text);@H_403_11@            textBox1.Text = "";@H_403_11@        }@H_403_11@@H_403_11@        private voID button13_Click(object sender,EventArgs e)  //“乘”按钮@H_403_11@        {@H_403_11@            temp = 3;@H_403_11@            num = Convert.Todouble(textBox1.Text);@H_403_11@            textBox1.Text = "";@H_403_11@        }@H_403_11@@H_403_11@        private voID button14_Click(object sender,EventArgs e)  //“除”按钮@H_403_11@        {@H_403_11@            temp = 4;@H_403_11@            num = Convert.Todouble(textBox1.Text);@H_403_11@            textBox1.Text = "";@H_403_11@        }@H_403_11@    }@H_403_11@}@H_403_11@ 总结

以上是内存溢出为你收集整理的c#-编写简易计算器全部内容,希望文章能够帮你解决c#-编写简易计算器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1212881.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存