How do I programmatically turn on number lock?

  • Thread starter Thread starter Anthony Davis
  • Start date Start date
A

Anthony Davis

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?
 
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.
 
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.

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
 
Jayesh said:
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
 
This is OEM dependant. Some OEMs (Symbol, Intermec etc) have libraries
that include functions to set the keyboard state.

Jon
 
Back
Top