Recent

Author Topic: TPanel.Repaint does not trigger OnPaint method  (Read 4480 times)

Muso

  • Sr. Member
  • ****
  • Posts: 356
TPanel.Repaint does not trigger OnPaint method
« 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

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: TPanel.Repaint does not trigger OnPaint method
« Reply #1 on: June 18, 2021, 08:17:45 pm »
I'm not sure. But I think you should not call Repaint, instead use TPanel.Invalidate;

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TPanel.Repaint does not trigger OnPaint method
« Reply #2 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

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TPanel.Repaint does not trigger OnPaint method
« Reply #3 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.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: TPanel.Repaint does not trigger OnPaint method
« Reply #4 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.

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: TPanel.Repaint does not trigger OnPaint method
« Reply #5 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..

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018