C#窗体实现的仿WIN10标准计算器

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
enum Operator2 { Plus, Subtract, Multiply, Divide }
int op2 = 0;//双目运算符指针
double sum = 0;//总和
bool pressedBI = false, pressedU = false;//按过双目、单目运算符
bool again = false;
public Form1()
{
InitializeComponent();
}
void CalculateBI(double second)
{
switch (op2)
{
case 0:
sum += second; break;
case 1:
sum -= second; break;
case 2:
sum *= second; break;
case 3:
sum /= second; break;
}
}

private void number_Click(object sender, EventArgs e)//数字点击事件
{
if (pressedBI || pressedU)
{
if (again) { sum = 0; op2 = 0; again = false; }
textBox1.Text = "0";
pressedBI = pressedU = false;
}
Button b = (Button)sender;
if (textBox1.Text != "0")
{
if (textBox1.Text.Length < textBox1.MaxLength)
textBox1.Text += b.Text;
}
else  textBox1.Text = b.Text;
}

private void Uoperator_Click(object sender, EventArgs e)//单目运算符点击事件
{
pressedU = true;
double Uresult = 0, num = Convert.ToDouble(textBox1.Text);
Button b = (Button)sender;
switch (b.Text)
{
case "√":
Uresult = Math.Sqrt(num); break;
case "x²":
Uresult = num * num; break;
case "¹/x":
Uresult = 1 / num; break;
}
textBox1.Text = Convert.ToString(Uresult);
if (pressedBI)
{
sum = Uresult; again = true;
}
}

private void BIoperator_Click(object sender, EventArgs e)//双目运算符、=点击事件
{
if (again) again = false;
if (!pressedBI)
{
CalculateBI(Convert.ToDouble(textBox1.Text));
textBox1.Text = Convert.ToString(sum);
}
Button b = (Button)sender;
switch (b.Text)
{
case "+":
op2 = (int)Operator2.Plus; break;
case "-":
op2 = (int)Operator2.Subtract; break;
case "×":
op2 = (int)Operator2.Multiply; break;
case "÷":
op2 = (int)Operator2.Divide; break;
case "=":
again = true; break;
}
pressedBI = true;
}

private void button11_Click(object sender, EventArgs e)//小数点
{
if (pressedBI || pressedU)
{
if (again) { sum = 0; op2 = 0; again = false; }
textBox1.Text = "0.";
pressedBI = pressedU = false;
}
int a = textBox1.Text.IndexOf('.');
if (a == -1)
{
if (textBox1.Text.Length < textBox1.MaxLength)
textBox1.Text += '.';
}
}

private void backspace_Click(object sender, EventArgs e)
{
if (!pressedBI && !pressedU)
{
string s = textBox1.Text;
if (s.Count() > 1)
textBox1.Text = s.Remove(s.Count() - 1, 1);
else textBox1.Text = "0";
}
}

private void C_Click(object sender, EventArgs e)
{
sum = 0;
op2 = 0;
textBox1.Text = "0";
}

private void CE_Click(object sender, EventArgs e)
{
if (again) { sum = 0; op2 = 0; }
textBox1.Text = "0";
}
}
}
C#新手，有什么不对的地方，欢迎指正。
11-23

09-17
06-12 2205
11-06 346
12-28
05-06
10-28 9461
10-25 1万+
04-29 2512