I have an application that runs on Windows CE and Windows Mobile (5.0+
for both) and has text fields that require numeric data only for some
fields and mixed numeric/text for others.
When the focus is on a text input that is numeric only, is there a way
that I can programmatically set the number lock button to on so that
the keys that are usually text are numbers?

RE: How do I programmatically turn on number lock? by srhartone

srhartone
Mon Jan 28 15:46:02 CST 2008

There is no way to do this. Usally you would override the OnKeyPress
protected method in a derived TextBox class or simply subscribe to the
KeyPress event of the TextBox class and handle key input as required. Check
for numerics etc if data is allowed bubble back up to the base class.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


"Anthony Davis" wrote:

>
> I have an application that runs on Windows CE and Windows Mobile (5.0+
> for both) and has text fields that require numeric data only for some
> fields and mixed numeric/text for others.
> When the focus is on a text input that is numeric only, is there a way
> that I can programmatically set the number lock button to on so that
> the keys that are usually text are numbers?
>

Re: How do I programmatically turn on number lock? by Jayesh

Jayesh
Mon Jan 28 19:03:58 CST 2008

On Jan 28, 1:46 pm, Simon Hart [MVP] <srhart...@yahoo.com> wrote:
> There is no way to do this. Usally you would override the OnKeyPress
> protected method in a derived TextBox class or simply subscribe to the
> KeyPress event of the TextBox class and handle key input as required. Check
> for numerics etc if data is allowed bubble back up to the base class.
> --
> Simon Hart
> Visual Developer - Device Application Development MVPhttp://simonrhart.blogspot.com
>
> "Anthony Davis" wrote:
>
> > I have an application that runs on Windows CE and Windows Mobile (5.0+
> > for both) and has text fields that require numeric data only for some
> > fields and mixed numeric/text for others.
> > When the focus is on a text input that is numeric only, is there a way
> > that I can programmatically set the number lock button to on so that
> > the keys that are usually text are numbers?

Hi,
You can copy this code and just wire up this event handler to your
textbox and you are done.
protected void NumericTextBox_KeyPress(Object sender,
KeyPressEventArgs e)
{
// Reject anything that isn't a number character or an
editting command
if ( !(Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)) )
{
e.Handled = true;
return;
}
}

Thanks,
Jayesh Modha

Re: How do I programmatically turn on number lock? by David

David
Tue Jan 29 05:28:24 CST 2008

Jayesh wrote:
> On Jan 28, 1:46 pm, Simon Hart [MVP] <srhart...@yahoo.com> wrote:
>> There is no way to do this. Usally you would override the OnKeyPress
>> protected method in a derived TextBox class or simply subscribe to the
>> KeyPress event of the TextBox class and handle key input as required. Check
>> for numerics etc if data is allowed bubble back up to the base class.
>> --
>> Simon Hart
>> Visual Developer - Device Application Development MVPhttp://simonrhart.blogspot.com
>>
>> "Anthony Davis" wrote:
>>
>>> I have an application that runs on Windows CE and Windows Mobile (5.0+
>>> for both) and has text fields that require numeric data only for some
>>> fields and mixed numeric/text for others.
>>> When the focus is on a text input that is numeric only, is there a way
>>> that I can programmatically set the number lock button to on so that
>>> the keys that are usually text are numbers?
>
> Hi,
> You can copy this code and just wire up this event handler to your
> textbox and you are done.
> protected void NumericTextBox_KeyPress(Object sender,
> KeyPressEventArgs e)
> {
> // Reject anything that isn't a number character or an
> editting command
> if ( !(Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)) )
> {
> e.Handled = true;
> return;
> }
> }
>
> Thanks,
> Jayesh Modha

That doesn't stop text being pasted into the textbox though.

D

Re: How do I programmatically turn on number lock? by Jon

Jon
Tue Jan 29 08:02:18 CST 2008

This is OEM dependant. Some OEMs (Symbol, Intermec etc) have libraries
that include functions to set the keyboard state.

Jon