Bypass character in textbox
-
Hi, How to bypass character in TextBox, so when we press alphabet keyboard key will bypass it. But when we press number TextBox will confirm this input. Thanx in advanced
Regard, Edwin :)
-
Hi, How to bypass character in TextBox, so when we press alphabet keyboard key will bypass it. But when we press number TextBox will confirm this input. Thanx in advanced
Regard, Edwin :)
-
private void txtBox__KeyPress(object sender, KeyPressEventArgs e) { if (!Char.IsDigit(e.KeyChar)) { e.Handled = true; // input is not passed on to the control(TextBox) } }
Thanx a lot -Bobo God Bless U
Regard, Edwin :)
-
Thanx a lot -Bobo God Bless U
Regard, Edwin :)
You need to do this: if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar) or otherwise your arrow/delete/etc keys will not work.
edwin46 wrote:
There is no KeyChar properties in e
It is constantly depressing to me, the inability of so many people to use intellisense, or google. Goodness knows what you're doing, but the KeyChar property is most certainly present. http://msdn2.microsoft.com/en-us/library/system.windows.forms.keypresseventargs.handled.aspx[^]
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi, How to bypass character in TextBox, so when we press alphabet keyboard key will bypass it. But when we press number TextBox will confirm this input. Thanx in advanced
Regard, Edwin :)
write your code in key press event
-
Hi, How to bypass character in TextBox, so when we press alphabet keyboard key will bypass it. But when we press number TextBox will confirm this input. Thanx in advanced
Regard, Edwin :)
Sorry Guys, It's working 100%
Regard, Edwin :)