Labels acting as buttons

Hello,
I needed a transparent button and, following a suggestion, I created a label with a MouseUp-MouseDown event. It works.
Now I’d like to have it do its job pressing the keyboard Return but I don’t seem to be able to do it. All events I pass get lost in some kind of limbo and nothing happens.
Is there a way to do it?
Thank you

The control that has the focus gets the keydown event.
If any of the controls that receive the message return true, the buck stops there.
If not, the active window should eventually get the event, assuming you add the event to the window.

You may try the window keydown event. But if a TextField has the focus, it will go to the TextField.

Using a label as a button will not work well with screen readers and other assistive devices.
Please only use this functionality for non-critical things like a website URL as a hyperlink in your About box.

A canvas could be focused. It would be a better solution.

in Linux you can make a PushButton transparent, maybe there are also Declares for OSX and Windows.

PushButton.Open

[code] declare sub gtk_button_set_relief lib “libgtk-x11-2” _
(btn as integer, relief as integer)
gtk_button_set_relief(me.Handle, 2)

declare sub gtk_button_set_focus_on_click lib “libgtk-x11-2” _
(btn as integer, b as Boolean)
gtk_button_set_focus_on_click(me.handle, false)[/code]

Excellent, and this is the one for Mac:

PushButton.Open

Declare Sub setBordered Lib "Appkit.framework" Selector "setBordered:" (id as integer, value as boolean) setBordered(me.handle, false)

If we can get a Windows declare from someone, maybe we can get a public no-background button class made.

Thanks everybody.
Tim’s suggestion works, I have it followed by an Action EventHandler. The only point is: if I put the button on top of a label (to have its caption look in a different color) it does not work anymore. It becomes transparent alright but does not respond to clicks.

Canvas. It can get focus, therefore tab stops and assistive support, as well as keydown for validation upon Return. It will show whatever color and font you want.

No need for convoluted stacking of button with declares on top of a label.

Curious, this compulsion for complexity programmers have …

Pardon me once more Michel, I understand you implement an AcceptFocus in the Open statement of the Canvas but where (and how) do you put a GotFocus and KeyDown events to have it act as a button at the press of the return key?
It works with MouseDow-MouseUp events, can’t find a way with the return key

The LR is your friend. You have all these events at your disposal, like in a button :

http://documentation.xojo.com/index.php/canvas

To emulate Action, return true in MouseDown, and place your code in MouseUp.

To enable click on Return, add the Keydown event and check for key=chr(13) before executing the code you need.

I would advise to subclass the canvas, so you can add an Action event, which can be raised from both mouseUp and KeyDown. But you can do the same with a regular instance : add a Button_Action method that you trigger from both MouseUp and KeyDown.

Thank you.
The MouseUp-MouseDown trick works fine.
I tried putting:
if Asc(Key)=13 then
TriVen.show //TriVen being a window
end if
in a KeyDown EventHandler of the Canvas but it does not react. I wonder if it should go somewhere else or if I need some kind of focusing the canvas prior to invoke the KeyDown. If this is the case where and how do I set focus to the canvas?

Keydown won’t work if the canvas is not focused. Exactly like a button.

Use the window keydown, and make sure to add code to every textfield keydown if you want it to react no matter what is focused.

if Asc(Key)=13 then

are you pressing the [RETURN] key or the [ENTER] key? they are NOT both AscB(13)

If AscB(key)=13 or AscB(key)=3 Then

assuming you have focus of course

Just the Return (I don’t have the Enter key, it’ the standard Apple keyboard).
It worked doing like Michel suggested, adding code to every textfield. Thank you.
I confess, though, I’m still very confused about the focus thing: how to set it and how to remove it

You can set focus with Canvas1.SetFocus() and also by setting the tab order. You can set the tab order in the gear pane of the inspector, so each time the user presses Tab, focus goes from one control to another, depending of what you set.

When the window opens it goes to the control that has tab setting zero, and then pressing tab goes along 1, 2, and so on.

Thanks for all your help