using System;
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 _125_计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnNum0_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum0.Text);
}
private void btnNum1_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum1.Text);
}
private void btnNum2_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum2.Text);
}
private void btnNum3_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum3.Text);
}
private void btnNum4_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum4.Text);
}
private void btnNum5_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum5.Text);
}
private void btnNum6_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum6.Text);
}
private void btnNum7_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum7.Text);
}
private void btnNum8_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum8.Text);
}
private void btnNum9_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnNum9.Text);
}
char Symbol;
private void btnAdd_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnAdd.Text);
Symbol = '+';
}
private void btnMinus_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnMinus.Text);
Symbol = '-';
}
private void btnMultiply_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnMultiply.Text);
Symbol = '*';
}
private void btnDivide_Click(object sender, EventArgs e)
{
txtDisplay.AppendText(btnDivide.Text);
Symbol = '/';
}
private void btnEqual_Click(object sender, EventArgs e)
{
double result;
string input = txtDisplay.Text;
if (Symbol == '+')
{
string[] nums = txtDisplay.Text.Split('+');
result = Convert.ToDouble(nums[0]) + Convert.ToDouble(nums[1]);
}
else if (Symbol == '-')
{
string[] nums = txtDisplay.Text.Split('-');
result = Convert.ToDouble(nums[0]) - Convert.ToDouble(nums[1]);
}
else if (Symbol == '*')
{
string[] nums = txtDisplay.Text.Split('*');
result = Convert.ToDouble(nums[0]) * Convert.ToDouble(nums[1]);
}
else if (Symbol == '/')
{
string[] nums = txtDisplay.Text.Split('/');
result = Convert.ToDouble(nums[0]) / Convert.ToDouble(nums[1]);
}
else
{
result = 999999999;
}
txtDisplay.Clear();
txtDisplay.Text = result.ToString();
}
private void btnC_Click(object sender, EventArgs e)
{
txtDisplay.Clear();
}
private void btnBack_Click(object sender, EventArgs e)
{
try
{
txtDisplay.Text = txtDisplay.Text.Substring(0, txtDisplay.Text.Length - 1);
}
catch
{ }
}
private void Form1_Load(object sender, EventArgs e)
{
// txtDisplay.Text = "0";
}
}
}