Lazarus

Programming => LCL => Topic started by: Muso on June 18, 2021, 04:17:24 pm

Title: TPanel.Repaint does not trigger OnPaint method
Post by: Muso on June 18, 2021, 04:17:24 pm
I have a TPanel. When I change its color and caption, I trigger repaint via
TPanel.Repaint.

To do something when the repaint is done, I added a procedure to the OnPaint method.

But the repaint does not trigger the OnPaint method. Is this a bug?
If not, what do I have to d at runtime to trigger the OnPaint method?

Lazarus 2.3.0 r65271 FPC 3.2.2 x86_64-win64-win32/win64
Title: Re: TPanel.Repaint does not trigger OnPaint method
Post by: Handoko on June 18, 2021, 08:17:45 pm
I'm not sure. But I think you should not call Repaint, instead use TPanel.Invalidate;
Title: Re: TPanel.Repaint does not trigger OnPaint method
Post by: winni on June 18, 2021, 08:26:44 pm
Hi!


Invalidate, Repaint, Update, Refresh do all the same but with different precedence.

All work with no problem with a panel.

If you start a big loop  only crunching numbers then you insert a

Code: Pascal  [Select][+][-]
  1. application.processMessages;

after the invalidate.

Otherwise you should show us some code.

Winni
Title: Re: TPanel.Repaint does not trigger OnPaint method
Post by: howardpc on June 18, 2021, 09:06:11 pm
I have a TPanel. When I change its color and caption, I trigger repaint via
TPanel.Repaint.
Changing a panel's color (or caption) triggers repainting. No additional manually added triggers are needed.

Is your application multithreaded?

If not, as winni states above, an Application.ProcessMessages call may be needed to allow the OS breathing time to respond to the paint messages.

If you want to "do something" whenever you change the panel's color or caption, invoke your own DoSomething procedure at that point. Don't make DoSomething depend on paint messages, which are the OS's responsibility and except in very rare circumstances should be completely ignored.

Otherwise you will quickly discover you are making endless recursive calls to Paint, and you will lock up your application.
Title: Re: TPanel.Repaint does not trigger OnPaint method
Post by: Muso on June 19, 2021, 02:06:59 am
Changing a panel's color (or caption) triggers repainting. No additional manually added triggers are needed.

Yes, and I found now out that this works also in other programs. I am stuck why even in debug mode changing the panel color does not call the OnPaint method. I tried to create a small example program, but there it works correctly.
Title: Re: TPanel.Repaint does not trigger OnPaint method
Post by: jamie on June 19, 2021, 03:30:07 am
If there is a transparent window overlaying it, you may not get a onPaint.

Also, if there is a clipping in the Canvas rectangle it may also not Onpaint because there is nothing to paint..

TinyPortal © 2005-2018