using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
double n1, n2;
string m = "";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = "";
label2.Text = "0";
}
private void button1_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button26_Click(object sender, EventArgs e)
{
//0
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button21_Click(object sender, EventArgs e)
{
//1
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button22_Click(object sender, EventArgs e)
{
//2
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button23_Click(object sender, EventArgs e)
{
//3
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button16_Click(object sender, EventArgs e)
{
//4
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button17_Click(object sender, EventArgs e)
{
//5
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button18_Click(object sender, EventArgs e)
{
//6
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button11_Click(object sender, EventArgs e)
{
//7
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button12_Click(object sender, EventArgs e)
{
//8
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button13_Click(object sender, EventArgs e)
{
//9
Button b = sender as Button;
if (label2.Text == "0")
label2.Text = b.Text;
else
label2.Text += b.Text;
}
private void button27_Click(object sender, EventArgs e)
{
//.
Button b = sender as Button;
label2.Text += b.Text;
}
private void button28_Click(object sender, EventArgs e)
{
//+
n1 = Double.Parse(label2.Text);
label1.Text = label2.Text + "+";
label2.Text = "";
m = "+";
}
private void button24_Click(object sender, EventArgs e)
{
//-
n1 = Double.Parse(label2.Text);
label1.Text = label2.Text + "-";
label2.Text = "";
m = "-";
}
private void button19_Click(object sender, EventArgs e)
{
//*
n1 = Double.Parse(label2.Text);
label1.Text = label2.Text + "*";
label2.Text = "";
m = "*";
}
private void button14_Click(object sender, EventArgs e)
{
///
n1 = Double.Parse(label2.Text);
label1.Text = label2.Text + "/";
label2.Text = "";
m = "/";
}
private void button25_Click(object sender, EventArgs e)
{
//=
if (label1.Text == "")
return;
double n2 = Double.Parse(label2.Text);
double c = 0;
switch (m)
{
case "+":
c = n1 + n2;
break;
case "-":
c = n1 - n2;
break;
case "*":
c = n1 * n2;
break;
case "/":
c = n1 / n2;
break;
}
label2.Text = c.ToString();
label1.Text = "";
}
private void button20_Click(object sender, EventArgs e)
{
//1/x
double n = Double.Parse(label2.Text);
label2.Text = (1 / n).ToString();
}
private void button10_Click(object sender, EventArgs e)
{
//根號
double n = Double.Parse(label2.Text);
label2.Text = (System.Math.Sqrt(n)).ToString();
}
private void button8_Click(object sender, EventArgs e)
{
//c
label1.Text = "";
label2.Text = "0";
}
private void button7_Click(object sender, EventArgs e)
{
//ce
label1.Text = "";
label2.Text = "0";
}
private void button6_Click(object sender, EventArgs e)
{
label2.Text = label2.Text.Remove(label2.Text.Length - 1);
if (label2.Text.Length == 0)
label2.Text = "0";
}
}
}
沒有留言:
張貼留言