How to use a keyboard on a programmed calculator
Dear Experts!
I have create a calculator in Window Form Application using C#, it is working very well, now I want your assistance to improve it further.
(1) The calculator works as long as you are using the clicking data way of input only.
(2) The calculator is part of the form like the input form.
Now I want your help on the following:
(1) How to allow the inputting of data through the keyboard as well
(2) In an event where I decide to create a project for this calculator, then how do I call it if I want to use it?
Please forgive me I’m a fun of VBA that is why my condition logic has something to do with VBA except convention from text to integer (Parse) and from integer to string (Tostring) which are purely C# products
Below is a full code for the said calculator:
I have create a calculator in Window Form Application using C#, it is working very well, now I want your assistance to improve it further.
(1) The calculator works as long as you are using the clicking data way of input only.
(2) The calculator is part of the form like the input form.
Now I want your help on the following:
(1) How to allow the inputting of data through the keyboard as well
(2) In an event where I decide to create a project for this calculator, then how do I call it if I want to use it?
Please forgive me I’m a fun of VBA that is why my condition logic has something to do with VBA except convention from text to integer (Parse) and from integer to string (Tostring) which are purely C# products
Below is a full code for the said calculator:
double total1 = 0;
double total2 = 0;
bool plusButtonClicked = false;
bool minusButtonClicked = false;
bool divideButtonClicked = false;
bool multiplyButtonClicked = false;
==================================================
//This calculator has buttons for inputing data
==================================================
private void btnOne_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnOne.Text;
}
private void btnTwo_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
}
private void btnThree_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnThree.Text;
}
private void btnFour_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnfour.Text;
}
private void btnFive_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnFive.Text;
}
private void btnSix_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSix.Text;
}
private void btnSeven_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSeven.Text;
}
private void btnEight_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnEight.Text;
}
private void btnNine_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnNine.Text;
}
private void btnZero_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnZero.Text;
}
private void btnPoint_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnPoint.Text;
}
==========================================================
// The above calculator need the operators below
==========================================================
private void btnClear_Click(object sender, EventArgs e)
{
plusButtonClicked = false;
minusButtonClicked = false;
divideButtonClicked = true;
multiplyButtonClicked = false;
txtDisplay.Clear();
}
private void btnMinus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
minusButtonClicked = true;
plusButtonClicked = false;
divideButtonClicked = false;
multiplyButtonClicked = false;
}
private void btnPlus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = true;
minusButtonClicked = false;
divideButtonClicked = false;
multiplyButtonClicked = false;
}
private void btnMultiply_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
minusButtonClicked = false;
plusButtonClicked = false;
divideButtonClicked = false;
multiplyButtonClicked = true;
}
private void btnDivide_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
minusButtonClicked = false;
plusButtonClicked = false;
divideButtonClicked = true;
multiplyButtonClicked = false;
}
private void btnEquals_Click(object sender, EventArgs e)
{
if (plusButtonClicked == true)
{
total2 = total1 + double.Parse(txtDisplay.Text);
}
else if (minusButtonClicked == true)
{
total2 = total1 - double.Parse(txtDisplay.Text);
}
else if (multiplyButtonClicked == true)
{
total2 = total1 * double.Parse(txtDisplay.Text);
}
else if (divideButtonClicked == true)
{
total2 = total1 / double.Parse(txtDisplay.Text);
}
txtDisplay.Text = total2.ToString();
total1 = 0;
}
private void btnClear_Click(object sender, EventArgs e)
{
plusButtonClicked = false;
minusButtonClicked = false;
divideButtonClicked = true;
multiplyButtonClicked = false;
txtDisplay.Clear();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.