Special TextBox Control

When you have a Resco CustomKeyboard in your application, maybe you need a custom TextBox too, which filters the pressed key.
In my sample code, the SpecialTextBox control overrides the TextBox control, and allows only these keys:
Space, 0-9, Enter.



SpecialTextBox overrides these 3 methods:
OnKeyDown, OnKeyUp and OnKeyPress.

Here is a piece of code to see how it works:

protected override void OnKeyUp(KeyEventArgs e)

{

if (e.KeyCode == Keys.Space ||

e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 ||

e.KeyCode == Keys.Enter)

{

base.OnKeyUp(e);

}

else

{

e.Handled = true;

}

}


When you want to import this control to your project with the source code, don't forget the DesignTimeAttributes.xmta, which allows the designer support for this control:

3 <Class Name="MyControls.SpecialTextBox">

4 <DesktopCompatible>trueDesktopCompatible>

5 <Class>



Sorce Code:
http://www.winmobile.euweb.cz/#Post06


0 comments:

Post a Comment