This is the 9th day of my participation in Gwen Challenge

demand

We’ve all used calculators at one point or another in our lives. So can we make our own calculator? Of course we can. Here I introduce a computer written by C#, you can use for reference.

Function is introduced

We need to key the 10 digits from 0 to 9, and also need four operations to add, subtract, multiply, divide, etc. The specific interface is as follows.

steps

1. Open VS and create a Windows Forms application

2. Select a project folder

According to their actual storage location, change.

3. Open the toolbox in the view and drag the relevant accessories to design the calculator page. Note that the name of the relevant buttons needs to be edited by yourself.

4. Double-click the relevant accessories to edit the code page.

I’m going to give it to you directly, and you should be aware that my component may not be the same as your own, so you can change it according to the name of your component.

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 WindowsFormsApplication2 { public partial class Form1 : Form { double a = 0; double b = 0; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { b = double.Parse(textBox1.Text); textBox1.Text += "+"; } private void button6_Click(object sender, EventArgs e) { textBox1.Text += "1"; } private void button7_Click(object sender, EventArgs e) { textBox1.Text += "2"; } private void button8_Click(object sender, EventArgs e) { textBox1.Text += "."; } private void button5_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); var res = dt.Compute(textBox1.Text, ""); textBox1.Text = Convert.ToString(res); } private void button2_Click(object sender, EventArgs e) { b = double.Parse(textBox1.Text); textBox1.Text += "-"; } private void button3_Click(object sender, EventArgs e) { b = double.Parse(textBox1.Text); textBox1.Text += "*"; } private void button4_Click(object sender, EventArgs e) { b = double.Parse(textBox1.Text); textBox1.Text += "/"; } private void button10_Click(object sender, EventArgs e) { textBox1.Text += "3"; } private void button9_Click(object sender, EventArgs e) { textBox1.Text += "4"; } private void button11_Click(object sender, EventArgs e) { textBox1.Text += "5"; } private void button12_Click(object sender, EventArgs e) { textBox1.Text += "6"; } private void button13_Click(object sender, EventArgs e) { textBox1.Text += "7"; } private void button14_Click(object sender, EventArgs e) { textBox1.Text += "8"; } private void button15_Click(object sender, EventArgs e) { textBox1.Text += "9"; } private void button16_Click(object sender, EventArgs e) { textBox1.Text += "0"; }}}Copy the code

To realize the page

Scan the QR code to obtain

More wonderful

Internet of Things knowledge

Click on it to see you look good

This article uses the article synchronization assistant to synchronize