PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: wxForm KeyDown event  (Read 744 times)

Johan Klassen

  • Junior Member
  • **
  • Posts: 107
  • FF3 User
wxForm KeyDown event
« on: July 24, 2020, 07:19:07 AM »

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: [Select]
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
« Last Edit: July 24, 2020, 07:26:51 AM by Johan Klassen »
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9322
  • Windows 10
    • PlanetSquires Software
Re: wxForm KeyDown event
« Reply #1 on: July 24, 2020, 08:41:04 AM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Johan Klassen

  • Junior Member
  • **
  • Posts: 107
  • FF3 User
Re: wxForm KeyDown event
« Reply #2 on: July 24, 2020, 10:06:18 AM »

thanks Paul  :)
that did the trick
Logged