Only Numbers in TextBox
Requirement: TextBox in C# should accept only numbers as input.
Solution:
Raise an event KeyPress and paste following line of code.
private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar))
e.Handled = true;
}
Here, e stands for the arguments of the function and e contains several attributes and methods like:
e.KeyChar : Character that has been pressed
e.Handled : Whether it is an acceptable character or not.
Related posts:
Continue reading » · Written on: 04-10-08 · No Comments »
Leave a Reply