Canvas does not accept focus with tab key

I have a small canvas that should act like a standard button - but it doesn’t.

I’m able to set the Tab Index, I’ve turned TabStop ON, I’ve enabled AcceptFocus and AcceptTabs, but the control is skipped when tabbing through.

It doesn’t show up in the Tab Order Editor, so I guess it is not really part of the tab order - but I wish it was.

WIN7
Xojo2016R3

Don’t know what to do next.

It works on macOS and I am afraid to say you are right, this does not works on Windows 10 (so I disabled it in a project).

Thanks Emile.

Ahh… Another Windows only issue. I’ll move this to the Windows Section.

I’m wondering if that in the preceding control I can use the KeyDown or keyUp event to test for the tab key then give focus to the canvas?

Worth a try, it’s not like I’ve got anything else better to do :slight_smile:

Sorry Xojo. For once this is documented: Canvas .

Search for: Simulating a Focus Ring on Windows and Linux.

A simple (bud bad) night was enough to… check the documentation ! :wink:

Thanks Emile.

I think I’ve sorted this out except that I haven’t yet created the code that would simulate a focus ring, but that bit is easy enough.

In the preceding control in the tab order, in the KeyDown Event:

If Keyboard.AsyncKeyDown(&h30) Then //tab key pressed btnMyCanvas.SetFocus() End If
In the KeyDown Event of btnMyCanvas:

If Keyboard.AsyncKeyDown(&h31) OR Keyboard.AsyncKeyDown(&h24) Then //spacebar or return key pressed // TEST MsgBox ("Spacebar or Return pressed.") // RUN the same method/code as in the MouseDown Event End If

As pointed out, using the tab key alone does not set the focus to the canvas control, but nevertheless, the tab order and index should be set as though it does, otherwise it will not be included in the tab loop - ie. when just tabbing through.

There could be issues that I haven’t seen, but I’ll put that down to “Known Unknowns”.

I’ll post the ‘focus ring’ example code when I have that working.

Cheers.

From the documentation:

[code]Simulating a Focus Ring on Windows and Linux

Unfortunately, a Focus Ring does not appear on Windows or Linux when a Canvas control gets the focus, but the GotFocus and LostFocus events fire normally. You can easily use them to simulate a focus ring. Create a property on the window called mHasFocus As Boolean.

In the GotFocus event handler:
mHasFocus = True
Canvas1.Invalidate

In the LostFocus event handler:
mHasFocus = False
Canvas1.Invalidate

In the Paint event handler for Canvas1:
#If TargetWin32 Or TargetLinux Then
If mHasFocus Then
g.ForeColor = HighlightColor // or FrameColor, whichever you wish
g.DrawRect(0, 0, Me.Width - 1, Me.Height - 1)
Else
g.ForeColor = RGB(178, 178, 178) // gray
g.DrawRect(0, 0, Me.Width - 1, Me.Height - 1)
End If
#Endif[/code]

Isn’t it good (Norwegian Wood) enough ?

Thank you Emile, but I want to finish this for myself.

I haven’t read the code you have posted (no offense). There is more than one way to achieve a “mock” focus ring. A simple rectangle or a more elaborate canvas picture, etc. I have my ideas.

It’s nothing too sexy, but it still does the job… Hmmm…, I think I heard my Wife say something very similar the other day.

Anyway, I’ll post my ‘focus ring’ example code when I have that working and/or when time permits.

[quote=357704:@Steve Kelepouris]It doesn’t show up in the Tab Order Editor, so I guess it is not really part of the tab order - but I wish it was.

WIN7
Xojo2016R3[/quote]

Odd, I’ve just fired up 2016r3 (Win10), added a textfield, a canvas and a textarea and all three show up in the “Tab Order” window.

When I turn on AcceptFocus and AcceptTabs for the canvas, run the project and press TAB a few times, the canvas definitely takes a tab stop as I need three TAB presses to cycle around my three controls.

Is your canvas placed straight on the window, or it is placed inside something else first?

Thanks Julian.

YES! the control IS inside another control - it seemed pretty innocuous, therefore I simply forgot. I feel like a bit of a goose. :slight_smile:

Also, I have the habit of setting the TabIndex of controls which I don’t want to be included to (-1) which removes them from the tab order, but that also removes the controls within that parent from the tab order.

I find the way the tab order works very very confusing. In FileMaker, which was my main tool previous to Xojo, there was an option to show the tab order. This displayed on the layout/window a small text field (in the shape of a tab arrow) next all the controls. You could simply change the tab order by typing in a number - very intuitive.

For some unknown reason, Xojo likes to re-start the tab order for every parent object that has controls within. Therefore allowing the same TabIndex number on the same window. Utter madness!!

I did read a while back on this forum a lengthy post on this issue, but due to some ‘non-helpful’ participants, I was left none the wiser.

Anyway, after a bit of fiddling around, all is working as it should.

Cheers.

Just in case…

In the WIndow Editor, Window view, Property pane, you have an icon to display some more properties including the Tab Index.

Also, you can display the window Controls Tab Order … in a Window and move the Control Order (top <-> bottom).

Edit: in prior version (forgot its date), we got the Tab order in a small square in each Control. That have been changed to the actual behavior.

Thanks Emile, I’m aware of all that.

What I’m getting at, and find disturbing, is that if you have a control within another control, then it cannot be separated and moved into the tab order that you may want using the Tab Order Editor.

Place a button within a rectangle, and you will see what I mean when you look at the tab order editor.

Also, no amount of changing the TabIndex will fix it.

AND, to make things worse, you can set the TabIndex (in the IDE) so as 2 controls have the same Index!!! WTF? So why bother having it at all - we should just use the tab editor.