简易计算器(只实现:+,-,*,/):
- 懂了求和,那么相应的-,*,/也就明白了
- 我给的代码,你复制粘贴,运行是运行不起的(这是窗体程序,不是控制台程序),那么你就看看代码,感受一下,它是如何实现简易计算器的功能的。
- 如果愿意下载的话,可以自己下载我上传的简易计算器的所有项目文件。(打开文件,就可以查看源代码,以及运行结果)
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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e)//求和 { string add1 = textBox1.Text; string add2 = textBox2.Text; float number1 = Single.Parse(add1); float number2 = Single.Parse(add2); float sum; sum = number1 + number2; textBox3.Text = sum.ToString(); } private void button2_Click(object sender, EventArgs e)//求减法 { string add1 = textBox1.Text; string add2 = textBox2.Text; float number1 = Single.Parse(add1); float number2 = Single.Parse(add2); float sum; sum = number1 - number2; textBox3.Text = sum.ToString(); } private void button3_Click(object sender, EventArgs e)//求除 { string add1 = textBox1.Text; string add2 = textBox2.Text; float number1 = Single.Parse(add1); float number2 = Single.Parse(add2); float sum; sum = number1 / number2; textBox3.Text = sum.ToString(); } private void button4_Click(object sender, EventArgs e)//求乘 { string add1 = textBox1.Text; string add2 = textBox2.Text; float number1 = Single.Parse(add1); float number2 = Single.Parse(add2); float sum; sum = number1 *number2; textBox3.Text = sum.ToString(); } } }
运行结果图:暂时没发。(没有截图工具························哭哭···················)