Hi all, I have been searching for days and cannot find any help. I need to be able to +*-/ all in one textbox.
as an example, 123+34*4+334-300. I am not using any buttons as the numpad on the keyboard is my buttons, but I want them all to work in my textbox like a calculator. I currently can do only add, no matter what character I use. Code:
private void calculatortxt_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsDigit(e.KeyChar) || e.KeyChar == (char)Keys.Back || e.KeyChar == '.' || e.KeyChar == '+' || e.KeyChar == '-' || e.KeyChar == '*' || e.KeyChar == '/'))
{ e.Handled = true; }
TextBox txtDecimal = sender as TextBox;
double Total;
string[] numbers = calculatortxt.Text.Split('+', '-', '*', '/');
Total = 0;
foreach (string value in numbers)
{
if (!string.IsNullOrEmpty(value))
{
Total = Total + Convert.ToDouble(value);
}
}
if (e.KeyChar == (Char)Keys.Enter)
{
//calculatortxt.Text = Total.ToString();
}
if (e.KeyChar == (Char)Keys.Escape)
{
calculatortxt.Text = "";
}
}