Hi Team;
I am new to programming and C#. I am creating a calculator form, and need to ensure the user enters a numeric only value (no empty values are valid).
I have 2 text boxes Value 1 & Value 2..The user must enter a numeric value only, and if not a message box should appear.
Here is what I got so far.
private void txValue1_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (!Char.IsDigit(ch) && ch != 8 && ch != 13)
e.Handled = true;
else
MessageBox.Show("You have entered an invalid value");
}
This isn't working for me...I don't know much about the error providor, nor the Validating / Validated events.
Also is it possible to validate both txtboxes at one, or do I need to enter the same code in both textboxes...
Can someone steer me in the right direction..
I hope I entered the code correctly....