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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hot Keys for Labels

Status
Not open for further replies.

Imaginecorp

IS-IT--Management
Jan 7, 2007
635
US
There has to be a better way...

I Know when a Hot Key (\<) is put on a label, and when "ALT+<<character>>" is pressed, the focus gets passed to the next control in the tab order.

I need the Click() Event of the label to fire when the “Hot Key” is used.

One way to circumvent this label default behavior, I have created a container class with a label and a command button. The command button is set to "Invisible", its Gotfocus() fires its click event. (The label, if clicked will fire the command buttons Click event)

This does what I want it to do, but is there something, someone here has done, a little bit more elegant and am I correct in my assumption of the label default behavior?

Any and all ideas will be greatly appreciated… Thanks
 
Imaginecorp,

Interesting problem.

If I was faced with this problem, I think I would have done what you are doing -- except that I would have put the functionality into a custom method of the container. That method would be called either from the label's Click or the button's GotFocus. But essentially, it is same idea as your solution.

The only othe possibility that springs to mind is trap the keystroke in the form's Keypress (with KeyPreview set .T.). The Keypress would call a method that tests the keystroke and decides which of the labels to invoke.

That would have the advantage that the single method would handle any number of labels on the same form. The disadvantage is that the label would no longer be self-contained. It would only work on forms that know about its behaviour. Also, I'm not sure if form's Keypress would take priority over the accelerator key (Alt+Letter) mechanism.

It'll be interesting to see what other folk suggest.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Also, I'm not sure if form's Keypress would take priority over the accelerator key (Alt+Letter) mechanism.

Hello Mike;
Unfortunately it does not. Trying to give this new client server application the look and feel of an Internet app... Could have used command buttons set to "plain" with the same background colour as the form but they still display their shape when in focus. Funny though, after posting, I did create a custom method in the container...
 
Hello Craig;
As the label can be clicked, the click() would fire the method in the container. The Mouse is not the problem... As this form is similar to POS screen, I need the Hot Keys as well.
The Hyperlink label is of no use in this situation as it does not respond to Hot Keys or at least it did not in a test I just ran based on your recommendation...
My class works great just thought I may be missing something to invoke the label "Click", via hot keys...
 
Imaginecorp,

Instead of an invisible command button, try an invisible textbox. I'd guess that it would work the same way, but it doesn't show the rectangle when it has focus.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I wonder why you still discuss. I don't see a better way of making use of the hotkey behaviour of labels. In fact what the help says about the behaviour is:

VFP help said:
A user can then press ALT and the specified character to move focus to that control. If the control is a command button, check box, or option button, pressing ALT and the specified character also has the effect of clicking the control.

That the focus moves to the next control in tab order, if you set the caption of a label is only a side effect of the label not being able to get focus, it only has a TabIndex property, but no TabStop and also no focus related events like When, GotFocus, LostFocus.

The only way of handling this is as you do add a control that can have focus, keep it visible, but out of the clipping area of the container you need to put around that label and the "focus control". But that can be anything able to get focus.

Bye, Olaf.
 
Like I stated earlier; the class works great and It seems there is no other way than what I am doing...
The way I have it is the labels click() and the Buttons Gotfocus() run a method in the container where the code resides. The Init() of the container moves the Button to the far left (-26) and sets the zOrder(1) , this way there is no chance of the button shape "leaking" through...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top