Im new to programming and I dont know very much about but I\'m making a calculator, and i want to use a textbox that only acepts numbers and decimals, and when the user past
useful for decimal numeric entry but has some bugs if (rightclick and paste) the other text. :D
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string original = (sender as TextBox).Text;
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
if (e.KeyChar == '.')
{
if (original.Contains('.'))
e.Handled = true;
else if (!(original.Contains('.')))
e.Handled = false;
}
else if (char.IsDigit(e.KeyChar)||e.KeyChar=='\b')
{
e.Handled = false;
}
}