Recent

Author Topic: TPageControl flickers when changing tab  (Read 4324 times)

Uto

  • New Member
  • *
  • Posts: 30
TPageControl flickers when changing tab
« on: February 15, 2015, 12:31:54 pm »
Hi All,

I have build an editor that uses a TPagecontrol and several TTabSheets, and inside each tabSheet there is SynMemo component that is used for editing, and uses $222827 background (dark). I have set shortcuts to access each tab but you can also change tabs by clicking on them. It happens that sometimes (often but not always) when you change tab by clicking on it, you can see a small flash in white, like some kind of flickering. This never happens if you use shortcuts to select tabs (what in the end changes Active Page by code).

It seems if you maximize the app it happens more often, so maybe related with some kind of "repaint" process... no idea.

May I be doing something wrong?

I have isolated the problem in the attached demo, in case anyone may want to have a look. Just maximize the application once it starts and change tabs by using mouse.

Thanks in advance.


balazsszekely

  • Guest
Re: TPageControl flickers when changing tab
« Reply #1 on: February 15, 2015, 12:45:22 pm »
Did you try PageControl1.DoubleBuffered := True ?

Uto

  • New Member
  • *
  • Posts: 30
Re: TPageControl flickers when changing tab
« Reply #2 on: February 15, 2015, 01:46:14 pm »
Thanks for the hint, but sadly I have tried the double buffered setting now, and also setting the doublebuffered property to true for tabsheets and SynMemo, but nothing changes.

I have tried to set tabsheet color to same color the SynEdit is, and made changes in ParentFont, ParentColor, etc.

Nothing seems to make that flickering dissappear.

I have found that this happens in Windows, but doesn't happen in linux (same code compiled in Lazarus for linux produces a non-flickering pageControl).

I'm using Lazarus 1.2.6 both in Windows and Linux, but it seems this may be happening since long ago:

http://forum.lazarus.freepascal.org/index.php?topic=6792.0


Uto

  • New Member
  • *
  • Posts: 30
Re: TPageControl flickers when changing tab
« Reply #3 on: February 15, 2015, 02:22:08 pm »
I  have tried a workaround by hiding tabs and replacing them by several buttons that simulate tabs, and after a basic test it doesn't flicker, so apparently it doesn't have to be with clicking or mouse, just with clicking on real tabs (if you change  activePageIndex by code, wether it is with a keyboard shortcut, or by clicking a button, then no flickering happens)


balazsszekely

  • Guest
Re: TPageControl flickers when changing tab
« Reply #4 on: February 15, 2015, 02:23:41 pm »
Since this is a windows only issue, disable the PageControl update, using the LockWindowUpdate command:
Drop a TTimer to your form, set Enabled property to False, Interval property to 100.

Code: [Select]
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ComCtrls, ExtCtrls {$IFDEF Windows}, windows{$ENDIF};

//...

procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean);
begin
  {$IFDEF Windows}
  if AllowChange then
  begin
    LockWindowUpdate(PageControl1.Handle);
    Timer1.Enabled := True;
  end;
  {$ENDIF}
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  {$IFDEF Windows}
  LockWindowUpdate(0);
  {$ENDIF}
end; 

You can play with the timer interval.

« Last Edit: February 15, 2015, 02:25:19 pm by GetMem »

Uto

  • New Member
  • *
  • Posts: 30
Re: TPageControl flickers when changing tab
« Reply #5 on: February 15, 2015, 03:10:51 pm »
Many thanks, it works fine with your solution. I reduced the timer interval to 20 and still no flickering  :D

Just for the records, if anyone is running the same issue you have to add the code above, and then on TimerTimer event:

Code: [Select]
procedure Txxxx.TimerTimer(Sender: TObject);
begin
 {$IFDEF Windows}
 LockWindowUpdate(0);
 Timer.Enabled:=false;
 {$ENDIF} 


 

TinyPortal © 2005-2018