G
Guest
Hi
How do I filter keys in a control, derived from TextBox so that my text box accepts only numbers (or only the keys I want, for that matter). I wrote the following code
class CustomTextBox:TextBox
...
protected override OnKeyDown(KeyEventArgs e
if (e.KeyCode!=Keys.A) // accept only the 'A' ke
{ Handled=true
els
{base.KeyDown
but the text box still displays all I the keys I press
I can override the OnTextChanged event and somehow keep track of what was pressed and change or not the text accordingly, but this is not the right way
Surely there must be a proper way to filter keys
Thank you
How do I filter keys in a control, derived from TextBox so that my text box accepts only numbers (or only the keys I want, for that matter). I wrote the following code
class CustomTextBox:TextBox
...
protected override OnKeyDown(KeyEventArgs e
if (e.KeyCode!=Keys.A) // accept only the 'A' ke
{ Handled=true
els
{base.KeyDown
but the text box still displays all I the keys I press
I can override the OnTextChanged event and somehow keep track of what was pressed and change or not the text accordingly, but this is not the right way
Surely there must be a proper way to filter keys
Thank you