主题:用C#写的计算器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Calculator.cs
{
public partial class Form1 : Form
{
Expression exp;
public Form1()
{
InitializeComponent();
exp = new Expression();
}
private void btn_Click(object sender, EventArgs e)
{
if (txtValue.Text == "0")
{
txtValue.Text = "";
}
Button o = sender as Button;
if (o != null)
{
txtValue.Text += o.Text;
}
}
private void Oper_Click(object sender, EventArgs e)
{
Button b = sender as Button;
if (b != null)
{
exp.x=double.Parse(txtValue.Text);
exp.flag = b.Text;
txtValue.Text = "0";
}
}
private void GetValue(object sender, EventArgs e)
{
exp.y = double.Parse(txtValue.Text);
txtValue.Text = exp.Value.ToString();
}
private void button19_Click(object sender, EventArgs e)
{
txtValue.Text = "0";
}
private void button20_Click(object sender, EventArgs e)
{
请各位高手够指点
this.Close();
}
}
public class Expression
{
public double x=0.0;
public double y=0.0;
public string flag="";
public double Value
{
get
{
double r=0.0;
switch (flag)
{
case "+":r=x+y;break;
case "-":r=x-y;break;
case "*":r=x*y;break;
case "/":r=x/y;break;
}
return r;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Calculator.cs
{
public partial class Form1 : Form
{
Expression exp;
public Form1()
{
InitializeComponent();
exp = new Expression();
}
private void btn_Click(object sender, EventArgs e)
{
if (txtValue.Text == "0")
{
txtValue.Text = "";
}
Button o = sender as Button;
if (o != null)
{
txtValue.Text += o.Text;
}
}
private void Oper_Click(object sender, EventArgs e)
{
Button b = sender as Button;
if (b != null)
{
exp.x=double.Parse(txtValue.Text);
exp.flag = b.Text;
txtValue.Text = "0";
}
}
private void GetValue(object sender, EventArgs e)
{
exp.y = double.Parse(txtValue.Text);
txtValue.Text = exp.Value.ToString();
}
private void button19_Click(object sender, EventArgs e)
{
txtValue.Text = "0";
}
private void button20_Click(object sender, EventArgs e)
{
请各位高手够指点
this.Close();
}
}
public class Expression
{
public double x=0.0;
public double y=0.0;
public string flag="";
public double Value
{
get
{
double r=0.0;
switch (flag)
{
case "+":r=x+y;break;
case "-":r=x-y;break;
case "*":r=x*y;break;
case "/":r=x/y;break;
}
return r;
}
}
}
}