using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 计算器
{
public partial class Form1 : Form
{
private bool ClearDisplay = true;
private string Operator;
private double Operand1;
private double Operand2;
private double result;
private System.Windows.Forms.Button btn;
public Form1()
{
InitializeComponent();
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}
private void HD(object sender, EventArgs e)
{
btn = (Button)sender;
if (ClearDisplay)
{
textBox1.Text = "";
ClearDisplay = false;
}
textBox1.Text = textBox1.Text + btn.Text;
}
private void HO(object sender, EventArgs e)
{
btn = (Button )sender;
Operator = btn.Text;
Operand1 = System.Convert.ToDouble(textBox1 .Text );
textBox1.Text = "";
}
private void button27_Click(object sender, EventArgs e)
{
double result = 0;
Operand2 = System.Convert.ToDouble(textBox1 .Text );
switch (Operator)
{
case "+":
result = Operand1 + Operand2;
// result = result + Operand1;
//result = result + Operand2;
//result = result + Operand1;
//result = result + Operand2;
break;
case "-":
result = Operand1 - Operand2;
break;
case "*":
result = Operand1 * Operand2;
break;
case "/":
if (Operand2 != 0)
result = Operand1 / Operand2;
else
{
MessageBox.Show("除数不能为零,请重新输入");
}
break;
}
textBox1.Text = result.ToString();
ClearDisplay = true;
}
private void button15_Click(object sender, EventArgs e)
{
result = -Convert.ToDouble(textBox1 .Text );
textBox1.Text = result.ToString();
}
private void button26_Click(object sender, EventArgs e)
{
if (textBox1.Text != "0")
{
result = 1 / Convert.ToDouble(textBox1.Text);
textBox1.Text = result.ToString();
ClearDisplay = true;
}
else
{
MessageBox.Show("除数不能为零,请重新输入除数!");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
}
老师 计算器的MS MC MR M+功能实现的代码怎么写。
}
} |