tags:

views:

61

answers:

1

Hello,

VS 2008 SP1

I want to capture the number keys 0 to 9. And perform some action if those number are clicked.

I am using the code below. However, it doesn't seem to be working right. However, the code doesn't go into the switch as when I use the debugger to see what key value has been captured in the e.KeyValue it comes up with "LButton | ShiftKey | Space".

However, should it not display NumPad1?

Many thanks for the advice,

 private void CATDialer_KeyDown(object sender, KeyEventArgs e)
        {
            // Play sound when use kits number key
            switch (e.KeyValue)
            {
                case Keys.NumPad1:
                    // Do something here
                    break;
            .
            .
            .
}
+1  A: 

I'm using this Code

private void tb_mds_port_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 8) // do something if backspace is pressed
    {
        // ACTION
        e.Handled = true;
    } 
}

For your code use something like this

if(e.KeyChar == (char)Keys.Return) // do something if return is pressed
{
   //ACTION
   e.Handled = true;
}
Henrik P. Hessel
Thanks. That solved my problem. However, just a quick question. Is there any real difference in using either keypress or keydown? Thanks.
robUK