Delphi Flicker Free with appearence

1.4k views Asked by At

If I create a simple app with a paint box and a scroll bar, draw some rectangles in the paint box, and make the scroll bar change refresh the paint box, I get a flicker free display when I drag the scrollbar (with DoubleBuffer set on the form):

procedure TMainForm.OnHorzChange(Sender: TObject);
begin
    PaintBox.Refresh;
end;

procedure TMainForm.OnPaint(Sender: TObject);
var
    x, y: integer;

begin
    with PaintBox.Canvas do
    begin
        Pen.Color := clBlack;
        Brush.Color := clGray;
        for y := 0 to 9 do
            for x := 0 to 9 do
                Rectangle(x * 32, y * 32, x * 32 + 24, y * 32 + 24);
    end;
end;

If I then change appearance to Carbon, the flicker returns:

program test;

uses
    Vcl.Forms,
    main in 'main.pas' {MainForm},
    Vcl.Themes,
    Vcl.Styles;

{$R *.res}

begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    TStyleManager.TrySetStyle('Carbon');
    Application.CreateForm(TMainForm, MainForm);
    Application.Run;
end.

So how can I use appearance and not get flickering? The setting double buffer on the main window doesn't stop the flickering.

2

There are 2 answers

0
EugeneK On BEST ANSWER

Put your PaintBox on the TPanel and set Panel.ParentBackground to False. In this case it does not flicker for me.

0
Uri S On

Another solution which has worked for me, is removing the seClient flag from the StyleElements propery of the TPanel or TScrollBox components.