Support Forums > WinFBX - Windows Framework for FreeBASIC

wxForm KeyDown event


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

--- 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)
Function = 0
End Function

--- End code ---
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.

Johan Klassen:
thanks Paul  :)
that did the trick


[0] Message Index

Go to full version