Good catch. A Button does receive focus when clicked, but it only displays its focus indicator when focus arrived through keyboard navigation. The Canvas previously exposed focus itself, but not that distinction, which is why flags became unreliable when a message box restored focus.
I’ve added a read-only FocusVisible property to Control for the next release (https://feedback.objo.dev/feature/1216). It is:
True after Tab or directional-key navigation.
False after mouse clicks, programmatic focus, modal restoration, or focus loss.
- Independent of
AllowFocusRing.
A custom Canvas button can now do this:
Sub Canvas1_FocusReceived()
Canvas1.Refresh()
End Sub
Sub Canvas1_FocusLost()
Canvas1.Refresh()
End Sub
Sub Canvas1_Paint(g As Graphics)
# Draw the button...
If Canvas1.FocusVisible Then
# Draw the custom focus ring...
End If
End Sub
Set Canvas1.AllowFocusRing = False when drawing the ring yourself. This should now behave consistently with a native Button, including after closing a message box.