Forum > LCL

repainting Form Canvas fails while window movement


Martin V:

I have got a strange behaviour. The application is a form where the Form.Canvas is drawn directly, it is a text editor.

When moving the window over the screen without changing the window size, I get Paint events. First, I wonder about this behaviour, because the operating system should make this job and the application shouldn't have the necessity of repainting.

Second, repainting fails in this case. I get an empty white form window. (White is the background color.) Paint seems to fill the canvas with the background color - I haven't programmed it -, and drawing has no effect, even the drawing code gets executed. I can restore the content by changing the window size, in this case repainting works.

To observe the behaviour, I have checked
- the cliprect region is the whole window
- the foreground color / font color is OK.

I have really no idea anymore what happend. Perhaps someone had a similar problem.

My questions are:
related to the first subject: Is it a bug or a feature that Paint events are generated if the window is moved and not resized
related to the second subject: What else can I test to understand the malfunction of failed repainting?

Debug sessions are difficult, because the activating/deactivating the test form changes the behaviour.

Thanks for any hints.

Martin V:

I have noticed now that Canvas.Height is zero in the paint message while moving the window. Because I need to calculate my graphical output coordinates, I read the false Canvas.Height value and recalculation of the cooridinates fails. A workaround is the usage of ClientHeight instead of Canvas.Height, now the program works. But it seems that this behaviour is not correct. I will send a bugreport in a few days if noone here answers.

I can't confirm this. I do not get paint events while moving and the Canvas.Height is non-zero. (GTK2)
Lazarus 0.9.29 r25483 FPC 2.4.0 i386-linux-gtk 2 (beta)

Martin V:
I made additional tests and when Canvas.Height is zero, I have the following in the "call stack" window (in reverse order)


That means, I do not get a paint message directly, I get a resize message which starts my redraw. Resize shouldn't be executed when moving the window.

My OS are Win2000 and Vista.


[0] Message Index

Go to full version