• Welcome to PlanetSquires Forums.
 

wxForm KeyDown event

Started by Johan Klassen, July 24, 2020, 07:19:07 AM

Previous topic - Next topic

Johan Klassen

hi Paul
in the early day of WinFBE I made a RPN calculator and as a calculator also needs to accept the numeric keys I added that functionality in the Form KeyDown event and it works great
however if I try to replicate that functionality in a new project it won't work, for example, if I add a text_box to the calculator and add the code

Function Form1_KeyDown( ByRef sender As wfxForm, ByRef e As EventArgs) As LRESULT
select case e.KeyCode
case VK_UP
Form1.Text1.Text = str(val(Form1.Text1.Text)+1)
case VK_DOWN
Form1.Text1.Text = str(val(Form1.Text1.Text)-1)
END SELECT
Function = 0
End Function

pressing the up-arrow will increment the number in the text-box and the down-arrow will decrement the number, but it I create a new project it won't work
it will work if instead of the Form1_KeyDown I do Text1_KeyDown then it works if Text1 has the focus but not otherwise

Paul Squires

Hi Johan,

Please make sure that you have set the "KeyPreview" property of the Form to "True". That will allow the Form to intercept the key press and send the message to your Form_KeyDown message handler.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Johan Klassen

thanks Paul  :)
that did the trick