FocusRing - Canvas Controls

In finishing off my Filter Control v1.1 I’ve been trying to sort a problem. If I deactivate a window where the canvas control has focus; the FocusRing doesn’t get cleared properly and I get the following left on my window…

Seems very similar to this bug left in feedback - 11396

Doing some debug seems to show that when I deactivate the window the canvas Paint event gets called twice, once with the Active property set to False and then immediately again with the Active flag set to True.

Anyone else seen this or have a workaround?

I haven’t seen that particular issue, but there’s a general problem with Canvas + FocusRing = very poor performance ( see <https://xojo.com/issue/26903> ) which could be related, if the underlying problem is “extra refresh events”?

Hi Patrick,

One way to prevent the Paint event from being called twice are to use two properties, which will likely increase Canvas performance:

This seems to prevent the double-firing of paint

Canvas.EraseBackground = False

When redrawing the Canvas, setting the invalidate (or refresh) command to false prevents the Paint event from erasing.

Invalidate(False)

The false argument greatly increases the speed of the canvas on Windows OS.

Hey Pat, Assuming this control is a container, put a canvas behind the control parts, leaving enough border for the focus ring. On the Mac, Invalidate(true) to force an erase. On Windows, Invalidate(false) and don’t actually do any drawing – if Windows isn’t leaving the focus ring around.

You might have a border as integer computed property to help users position it properly.

Thanks for the replies

Michael - Personally I think it’s more to do with 2 paint events getting fired but I’ll dig a bit deeper, I’ve appended a project to 11396 to get some Xojo Engineer feedback

Eugene - it’s only a problem on the Mac which really should have been pointed out on my original post!! I’ve had a play with these properties but didn’t seem to make a difference, could be I’ve missed something though. I’ll try again - cheers

Brad - Sorry Fella - the control is a canvas not a container :slight_smile: