实现普通计算器的一些功能
布局也就是一般计算器的布局
1到9的按钮:
private void n1_Click(object sender, EventArgs e) // 按钮1的代码,1到9换个数字就行
{
if (c == true)
{
textBox1.Text = "";
c = false;
}
textBox1.Text += "1";
}
8个操作运算的代码:
private void jia_Click(object sender, EventArgs e) //加号的代码,其他的换符号就行
{
c = true;
b = double.Parse(textBox1.Text);
d = "+";
}
等号代码:
private void dengyu_Click(object sender, EventArgs e)
{
switch (d)
{
case "+": a = b + double.Parse(textBox1.Text); break;
case "-": a = b - double.Parse(textBox1.Text); break;
case "*": a = b * double.Parse(textBox1.Text); break;
case "/": a = b / double.Parse(textBox1.Text); break;
case "x^2": a = b * b; break;
case "sqrt": a = Math.Sqrt(b); break;
case "log": a = Math.Log10(b); break;
case "ln": a = Math.Log(b); break;
}