计算器项目需求
一、界面设计
1.做一个显示屏
2.17个button按钮(0-9,±×÷=%,CE)
二、需要实现的功能
1.输入第一个数字
2.选择运算符号
3.输入第二个数字
4.按下等号计算结果,结果显示在显示屏上
三、实现步骤
1.先做界面
a. 显示屏 textbox / listbox / label
b. 按钮 使用17个button,button上的文本改成对应的符号
2.
补充,申请两个int变量,第一个num1,装第一个数字,第二个num2,装第二个数字
a.输入第一个数字,当点击一个数字按钮时,屏幕上显示一个,之前显示的数字在前面呆着
a1.添加数字按钮的点击事件
a2.事件触发,将按钮代表的数字显示textbox1的text
b.当输入符号的时候,清除屏幕,但是后台必须记录好第一个数字
b1.添加符号按钮的点击事件
b2.点击任何一个符号按钮,用一个变量装刚才输入的textbox1中的数字
c.输入第二个数字
d.按下等号按钮,显示屏上的改变成两个数字的运算结果
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 Form5 : Form
{
public Form5()
{
InitializeComponent();
}
//1
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "1";
}
//2
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "2";
}
//3
private void button3_Click(object sender, EventArgs e)
{