Drawing to FireMonkey TControl.Canvas outputs to TForm Canvas


I’ve just started transitioning a huge codebase to FireMonkey but I’m having some difficulties.

One thing tripping me up is a major gotcha with TControl.Canvas. If I don’t call it correctly, then drawing to the TCanvas, actually draws to the form canvas (to be specific, it draws at 0,0 on the form, rather than the client origin of my custom control).

For example, in a MouseMove event I need to draw a selection. Here is some example code:

procedure TMyCustomControl.MouseMove(Shift: TShiftState; sX, sY: Single);


procedure TMyCustomControl.Paint();

Using this code in FireMonkey, painting is to the form (i.e. outputs at 0,0 on the form).

If I change the code in MouseMove to Repaint(); then it paints correctly to my control.

Clearly, with FMX, I need to trigger the control’s actual painting (not just paint directly), otherwise the Canvas is not valid.

What I need is an explanation as to why it functions like this. I have a lot of canvas drawing in my code, so I need to understand this so I can hunt out other incompatible code.

System: Delphi 10.3 Rio, 32 or 64bit Windows apps.

Comments are closed.