Untitled
unknown
csharp
2 years ago
5.6 kB
13
Indexable
namespace Simple_Calculator
{
public partial class Form1 : Form
{
private decimal valueFirst = 0.0m;
private decimal valueSecond = 0.0m;
private decimal Result = 0.0m;
private decimal operators = '+';
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ZeroBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "0";
}
else
{
textBox.Text += "0";
}
}
private void DotBtn_Click(object sender, EventArgs e)
{
if (!textBox.Text.Contains("."))
{
textBox.Text += ".";
}
}
private void OneBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "1";
}
else
{ textBox.Text += "1"; }
}
private void TwoBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "2";
}
else
{ textBox.Text += "2"; }
}
private void ThreeBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "3";
}
else
{ textBox.Text += "3"; }
}
private void FourBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "4";
}
else
{ textBox.Text += "4"; }
}
private void FiveBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "5";
}
else
{ textBox.Text += "5"; }
}
private void SixBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "6";
}
else
{ textBox.Text += "6"; }
}
private void SevenBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "7";
}
else
{ textBox.Text += "7"; }
}
private void EightBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "8";
}
else
{ textBox.Text += "8"; }
}
private void NineBtn_Click(object sender, EventArgs e)
{
if (textBox.Text == "0")
{
textBox.Text = "9";
}
else
{ textBox.Text += "9"; }
}
private void PlusMinusBtn_Click(object sender, EventArgs e)
{
if (textBox.Text.Contains("-"))
{
textBox.Text = textBox.Text.Trim('-');
}
else
{
textBox.Text = "-" + textBox.Text;
}
}
private void SubtractionBtn_Click(object sender, EventArgs e)
{
valueFirst = decimal.Parse(textBox.Text);
textBox.Clear();
operators = '-';
}
private void AdditionBtn_Click(object sender, EventArgs e)
{
valueFirst = decimal.Parse(textBox.Text);
textBox.Clear();
operators = '+';
}
private void DivitionBtn_Click(object sender, EventArgs e)
{
valueFirst = decimal.Parse(textBox.Text);
textBox.Clear();
operators = '/';
}
private void MultiplicationBtn_Click(object sender, EventArgs e)
{
valueFirst = decimal.Parse(textBox.Text);
textBox.Clear();
operators = '*';
}
private void EqualBtn_Click(object sender, EventArgs e)
{
switch (operators)
{
case '-':
valueSecond = decimal.Parse(textBox.Text);
Result = valueFirst - valueSecond;
textBox.Text = Result.ToString();
break;
case '+':
valueSecond = decimal.Parse(textBox.Text);
Result = valueFirst + valueSecond;
textBox.Text = Result.ToString();
break;
case '*':
valueSecond = decimal.Parse(textBox.Text);
Result = valueFirst * valueSecond;
textBox.Text = Result.ToString();
break;
case '/':
valueSecond = decimal.Parse(textBox.Text);
Result = valueFirst / valueSecond;
textBox.Text = Result.ToString();
break;
}
}
private void ClearBtn_Click(object sender, EventArgs e)
{
valueFirst = 0.0m;
valueSecond = 0.0m;
textBox.Text = "0";
}
}
}
Editor is loading...
Leave a Comment