In this tutorials will teach how to make a calculator in C#.net windows form application step by step. How to create the calculator in C#.net application in best coding practice.
string CalTotal;
int num1;
int num2;
string option;
int result;
private void btn1_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "1";
}
private void btn2_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "2";
}
private void btn3_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "3";
}
private void btn4_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "4";
}
private void btn5_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "5";
}
private void btn6_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "6";
}
private void btn7_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "7";
}
private void btn8_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "8";
}
private void btn9_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "9";
}
private void btn0_Click(object sender, EventArgs e)
{
txtTotal.Text = txtTotal.Text + "0";
}
private void btnPlus_Click(object sender, EventArgs e)
{
option = "+";
num1 = int.Parse(txtTotal.Text);
txtTotal.Clear();
}
private void btnMin_Click(object sender, EventArgs e)
{
option = "-";
num1 = int.Parse(txtTotal.Text);
txtTotal.Clear();
}
private void btnMul_Click(object sender, EventArgs e)
{
option = "*";
num1 = int.Parse(txtTotal.Text);
txtTotal.Clear();
}
private void btnDiv_Click(object sender, EventArgs e)
{
option = "/";
num1 = int.Parse(txtTotal.Text);
txtTotal.Clear();
}
private void btnEql_Click(object sender, EventArgs e)
{
num2 = int.Parse(txtTotal.Text);
if (option.Equals("+"))
result = num1 + num2;
if (option.Equals("-"))
result = num1 - num2;
if (option.Equals("*"))
result = num1 * num2;
if (option.Equals("/"))
result = num1 / num2;
txtTotal.Text = result + "";
} private void btnClear_Click(object sender, EventArgs e)
{
txtTotal.Clear();
result = (0);
num1 = (0);
num2 = (0);
}
What Is the Tesla Pi Phone? Imagine if Tesla, the company that makes famous…
Inventory Management POS systems are now an essential part of modern businesses such as bookshops,…
If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…
GitHub is a powerful tool used by teams and developers around the globe. This guide is…
It's like having a super-smart buddy that is always there to help you write stories,…
The UK is known for its rich history, diverse culture, and most of all its…