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 strongm 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 focus textbox 1

Status
Not open for further replies.

mstrcmtr

Programmer
Nov 14, 2007
103
PK
How can focus text box with the help of following command

ON Key Label Alt+z
 
Whatever you define with ON KEY LABEL will run as if EXECSCRIPT is done, outside of any scope. You don't have the THISFORM context. Therefore donÄt try to do this with ON KEY LABEL.

What VFP recommends is using a caption with "\<" prefixing the letter you want to be an Access key to the control, see
[URL unfurl="true"]https://docs.microsoft.com/en-us/previous-versions/visualstudio/foxpro/zahzb3bz(v%3dvs.80)[/url]

As the example states for a caption "\<Open" ALT+O becomes an access key. That doesn't only work with controls having a caption like the command button or a checkbox or option of an option group, this works for a separate label control, too, in conjunction with the tab stop mechanism: As a standalone Label doesn't get focus but can be assigned a tab index, the focus will go to the control with next tab index after that.

So if you assign tab order correctly '(Menu: View->Tab Order -> Assign interactively or by list helps to not need to set all tabindex properties manually), you can use a Label next to a Textbox to give focus to the textbox. Let's say the label has tabindex 15 and the textbox has tabindex 16, then that label becomes the landing point to get focus to the textbox.

As you want ALT+Z, that's in conjunction. All you need is a label that has a Z as access key, like "Peanutbutter \<Zandwich" and the magic happens.

Bye, Olaf.



Olaf Doschke Software Engineering
 
You've got to remember that a user can hit your chosen key combination (ALT+Z in this case) at any time, in any part of the application. But your textbox is only active when the relevant form is open and active. If you try to give focus to the textbox by means of ON KEY LABEL at any other time, it will cause an error.

For that reason, ON KEY LABEL is a bad choice in this case. In fact, it's a bad choice in almost all cases, and should generally be avoided.

If your aim is give the user a shortcut key to access a given textbox, you can do that more easily with the usual [tt]\<[/tt] mechanism (as mentioned by Olaf, above). If you are not sure how that works, simply place [tt]\<[/tt] before the relevant letter in the textbox's caption. (By which I mean the caption of the label that immediately precedes the textbox in tab order.)

For example, if the textbox contains the address of a zoo, you would write the caption of the label as [tt]Address of \<zoo[/tt]. The letter Z will appear underlined. If the user than hits ALT+Z, that will immediately give focus to the textbox.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Already in Hacker's Guide to VFP6, Tamar, Ted and Steven wrote about the use of keypress and keypreview for reacting to user input individually without having those problems that come with ON KEY LABEL.

Jump to Hacker's Guide to VFP6

I implemented the keypress and keypreview feature by adding a property for usable Shortcuts in each class that might have the need for a shortcut. The prop is called ._FKeysAllowed and can hold a comma-seperated list of shortcuts like "F1,F3,CTRL+Y,CTRL+P" a.s.o. and in keypreview(form)/keypress(object) I check the current objects prop-value and ignore or react to it.

JM2C



-Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top