Just change the event to be handled to "keyDown" instead of "keyPress". keyPressEventArgs doesn't have a definition for keyCode, but keyChar.
this.KeyDown += new KeyEventHandler(this.frmPO
private void frmPOSAddMultipleItems_Key
{
// Initialize the flag to false.
NonNumberEntered = false;
// Determine whether the keystroke is a number from the top of the keyboard.
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
// Determine whether the keystroke is a number from the keypad.
if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
{
// Determine whether the keystroke is a backspace.
if(e.KeyCode != Keys.Back)
{
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
NonNumberEntered = true;
}
}
}
}
Main Topics
Browse All Topics





by: wenyonkPosted on 2005-03-17 at 10:43:10ID: 13567839
The line below is in the Component Initialize section for the form:
essEventHa ndler(this .frmPOSAdd MultipleIt ems_KeyPre ss);
this.KeyPress += new System.Windows.Forms.KeyPr