[Lazarus] Calling DrawFocusRect() outside the Paint() event

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Oct 10 11:49:32 CEST 2016

On Mon, 10 Oct 2016 10:21:48 +0100
Graeme Geldenhuys via Lazarus <lazarus at lists.lazarus-ide.org> wrote:

> Hi,
> Working on a visual report designer for the upcoming fpReport. We use
> Canvas.DrawFocusRect() to draw a selection rectangle around a reporting
> element (eg: a memo). We can drag that rectangle around in the report
> designer (which itself is a custom widget). We call the
> Canvas.DrawFocusRect() from within the MouseMove event. It seems to work
> fine under LCL-GTK2, but could this be problematic on other platforms,
> as painting outside the Paint event can normally have undefined results.

Some widgetsets like Carbon can only paint during the Paint event.

> Or has LCL somehow resolved the issues of painting outside the Paint event?

If you want to optimize for mini changes like the focusrect you might
want to use a bitmap. 

> On a side note:
>   The Paint() event for the report designer can potentially have very
> lengthy code, so we definitely don't want to repaint everything simply
> because we are dragging a focus rectangle around on the canvas. So if we
> must, we can obviously work around this by using various states in the
> Paint method.

You need to optimize the Paint event anyway.
You don't need to draw everything when using InvalidateRect instead
of Control.Invalidate.
And in Paint use Canvas.GetClipRect or lclintf's GetClipRGN to avoid
unnecessary calculations.


More information about the Lazarus mailing list