Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ON KEY LABEL Help! 2

Status
Not open for further replies.

fkwong

Programmer
Jul 5, 2002
65
US
I have a data entry form which include a container class that has navigation buttons in it.

I would like to assign ON KEY LABEL to each of the button so that the user can press ALT+F to execute the 'Search' botton. I put the ON KEY LABEL command in the 'Activate' event for the main form.

THe following line of code return a error ("THISFORM can only used within a method."). Please help and give advice.

ON KEY LABEL ALT+F THISFORM.grptoolbar.jk_cmdbtn10.click

(I am not sure the above code is correct but I would like to automatic click the button when ALT+F is pressed...)

Please advice.
 
Assuming this is the only form active, you can use:
Code:
ON KEY LABEL ALT+F _SCREEN.ActiveForm.grptoolbar.jk_cmdbtn10.click()
Rick
 
Two things: It's recommended NOT to "run" an event (such as by calling THISFORM.pageframe.pageX.cmdButton.Click) but instead make the button click event call THISFORM.DoWhatever, then anywhere else that Whatever has to happen, just THISFORM.DoWhatever. That way the rest of your code doesn't end up reliant upon the UI structure of your form (such as if you later take out/add pageframes).

Second, THISFORM is not accessible from an ON KEY.
You can try:
ON KEY LABEL ALT+F _VFP.ActiveForm.grptoolbar.jk_cmdbtn10.click

But this "on key" will still be active when a different form is active. (If the form is modal, this isn't a problem -- it's easy to manage the ON KEY's in INIT/UNLOAD)

 
Even better would be to establish a hotkey framework for your application. For example:

ON KEY LABEL ALT+F Do appHotKey WITH "ALT+F"

Then in your main .PRG, have a procedure AppHotKey:

PROCEDURE AppHotKey( pcHotKey )
LOCAL lcHotKey
IF VARTYPE(_VFP.ActiveForm.HotKeysActive)='L' ;
AND _VFP.ActiveForm.HotKeysActive
_VFP.ActiveForm.HotKey(lcHotKey)
ENDIF
ENDPROC

Then, in any form that should have hotkeys, create a "HotKeysActive" property and a "HotKey" method, (or beter yet, put these definitions in your base Form class) and handle the hotkey there.
 
Wong,

There's even more simlpe solution than the above if it's a form indeed and you use VFP IDE vor visual design:

Bring up a form in the form designer, select your &quot;Search&quot; button, then mouse-right-click-&quot;Properties&quot;, select Layout tab, select Caption, type in the entry box &quot;Search (Ctrl+\<F)&quot; (no quotes, of course) and hit Enter. See what happens.

In essence, &quot;\<&quot; in Caption in VFP is equivalent of &quot;&&quot; in VB, that is create shortcut or hot key.

I hope this helps.

Regards,

Ilya


 
OKL's should be avoided when ever possible. Hot keying the label is a good idea, so is writing code in the forms keypress event. Or better yet your form classes keypress event. Remeber to turn keypreview on so the form gets the keystroke before the controls if you are going to do it that way.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top