views:

356

answers:

1

How Do I Make Button.click Event Perform both the enter and period(del) keys on the numeric keypad?

Code snippet:

Private Sub frmCalc_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
     Select Case e.KeyCode
        Case Keys.NumPad0
            btn0.PerformClick()
        Case Keys.NumPad1
            btn1.PerformClick()
      'etc.
    End Select
End Sub


Case Keys.Enter and Case Keys.Separator do not work. Nor does anything like Keys.OEMPeriod for the period(del) key.

I've also tried calling the enter key in a KeyPress event etc. But to no avail.

Any ideas? I'm trying to mimic Windows calc.exe for a school project and thought I'd try throwing in a few extras such as numeric keypad functionality.

+1  A: 

You can figure this out by yourself.

Set a breakpoint at the beginning of your KeyDown handler in the debugger, press one of those keys, and check the value of e.KeyCode in the Locals window.

SLaks
Thanks, much appreciated!This solved the problem for the "period" key. However, pressing the enter key doesn't show any values in the Locals window. Any ideas as to why this might be?
legostyle
When I set a breakpoint at the beginning of the KeyDown handler in the debugger and start debugging, the Locals window remains completely empty when I press any of the Enter keys on the keyboard, whereas if I press e.g. the a key the Locals window states Name e, Value {KeyData = A{65}} etc. I'm confused as to why the Enter key doesn't seem to respond at this point.
legostyle
When you press Enter, does the breakpoint get hit at all?
SLaks
No, strangely enough nothing happens. No yellow arrow appears in front of the set breakpoint nor does any text appear in the Locals window when the Enter key is pressed.
legostyle
Run Spy++ and check what messages your control receives when you press Num Enter
SLaks