标题:
存储功能实现
[打印本页]
作者:
侯艳飞
时间:
2010-1-6 09:12
标题:
存储功能实现
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+功能实现的代码怎么写。
}
}
作者:
fwbook
时间:
2010-1-7 08:48
这个只要搞清楚这几个键的功能,就可以了。例如M+,就是将现在的结果保存起来,然后和后面的结果进行相加。对于这样的一个值,你可以单独放一个变量来保存。这个变量初始值为0。当按下M+的时候,就把现在的结果保存到变量中。每次M+的值都保存起来,就可以了。
欢迎光临 万卷图书 (http://wanjuanchina.net/)
Powered by Discuz! 7.0.0