Only allow numbers in textbox
//In this scenario it only allows digits
1 2 void textBox_KeyPress(object sender, KeyPressEventArgs e) 3 { 4 e.Handled = !(Char.IsDigit(e.KeyChar) || e.KeyChar == '\b'); 5 }
DZone Snippets > dubby > source
12736 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 void textBox_KeyPress(object sender, KeyPressEventArgs e) 3 { 4 e.Handled = !(Char.IsDigit(e.KeyChar) || e.KeyChar == '\b'); 5 }