Recent

Author Topic: [SOLVED] tcustomcontrol and paint  (Read 6468 times)

GetMem

  • Hero Member
  • *****
  • Posts: 3783
Re: tcustomcontrol and paint
« Reply #15 on: August 25, 2017, 11:28:33 am »
Hi apeoperaio,

Add this to your custom control:
Code: Pascal  [Select][+][-]
  1.   //...
  2.  TMyDrawingControl = class(TCustomControl)
  3.   private
  4.     FRedGrid: boolean;
  5.     procedure SetRedGrid(AValue: boolean);
  6.   protected
  7.     procedure Resize; override; //<--this line
  8.   public
  9.     procedure Paint; override;
  10.     property RedGrid: boolean read FRedGrid write SetRedGrid;
  11.   end;
  12.  
  13. //...
  14.  
  15. procedure TMyDrawingControl.Resize;
  16. begin
  17.   Invalidate;
  18.   inherited Resize;
  19. end;

apeoperaio

  • Full Member
  • ***
  • Posts: 189
Re: tcustomcontrol and paint
« Reply #16 on: August 25, 2017, 11:53:29 am »
It works.

Actually I have two solutions, overriding SetBounds or Resize method and add Invalidate to that.
Which one should I choose?

Since I need it only for Linux, is it a bug?

taazz

  • Hero Member
  • *****
  • Posts: 5365
Re: tcustomcontrol and paint
« Reply #17 on: August 25, 2017, 01:17:23 pm »
It works.

Actually I have two solutions, overriding SetBounds or Resize method and add Invalidate to that.
Which one should I choose?
anyone setbounds is used to actually change the size and position of your control before exiting it call the resize method so the onresize event can be called. calling invalidate etiher on the begining or the end of that process makes no difference (on windows at least) it will be processed after the resize has finished.
Since I need it only for Linux, is it a bug?
No, I wouldn't characterize it as a bug, its widget set behavior they chose to do it that way for speed reasons you just need to inform the widget that you require a fill repaint.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

apeoperaio

  • Full Member
  • ***
  • Posts: 189
Re: tcustomcontrol and paint
« Reply #18 on: August 25, 2017, 03:14:04 pm »
Thanks for the explanation!
« Last Edit: August 25, 2017, 03:25:46 pm by apeoperaio »

 

TinyPortal © 2005-2018