点击vs2019 IDE 中的视图-> 工具箱子,
在工具箱中找到Button,点击后,拖动到主界面上,形成下面的形式
为什么你的按钮是button? 右键点击button-> 属性,vs2019右边栏会出现
修改Text栏为1,然后以此拖动9个按钮,并修改按钮的文字,并且把 button 的属性中的(name) 改为 btn_1,btn_2,btn_3等。
然后再Form1中双击每一个按钮,就可以形成buttonclick按钮的函数。
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Btn_1_Click(object sender, EventArgs e)
{
}
private void Btn_2_Click(object sender, EventArgs e)
{
}
private void Btn_3_Click(object sender, EventArgs e)
{
}
private void Btn_4_Click(object sender, EventArgs e)
{
}
private void Btn_5_Click(object sender, EventArgs e)
{
}
private void Btn_6_Click(object sender, EventArgs e)
{
}
private void Btn_7_Click(object sender, EventArgs e)
{
}
private void Btn_8_Click(object sender, EventArgs e)
{
}
private void Btn_9_Click(object sender, EventArgs e)
{
}
private void Btn_0_Click(object sender, EventArgs e)
{
}
private void Btn_add_Click(object sender, EventArgs e)
{
}
private void Btn_equal_Click(object sender, EventArgs e)
{
}
}
}
然后还需要一个textBox来展示 输入的数字,和计算结果。
以上是我的每一个按钮双击后的样子。剩下的就是编写计算器的逻辑部分了。