Hi,

I tryed to run on win32 the exact same code that worked perfectly on gtk, but it gave me a lot of flickering. I simplified the code to locate the problem and I have basicaly a timer running at 10Hz and a custom control. The timer tell the control to repaint. The image is first drawn to a bitmap and then to the canvas.

First I thought it was a problem on Lazarus, but then I put this code on Delphi and it also flickers. It also flickers on wine.

I googled for some time without sucess. Tryed some methods, like:
- Set double buffer for the form
- Add opaque to the control states
- Use a different method to draw the bitmap on the canvas
- Use a different method to repaint the image on the timer
- Removing the bitmap and painting directly to the Canvas

And I was about to post asking for help when I found a answer. Simply set DoubleBuffered for the control ... strange.

I´m just posting because it may help someone else ^^ (and I have already written the text when I found the solution).

thanks,

With lucky I will have a multi-platform opensource osciloscope written partially on Lazarus on a month or two.

here is the code:

type
  TTela = class(TCustomControl)
  public
    procedure Paint; override;
  end;

  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    Tela: TTela
----

procedure TTela.Paint;
var
  x, y: Integer;
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.Height := Height;
    Bitmap.Width := Width;

    Bitmap.Canvas.Pen.Color := clWhite;
    Bitmap.Canvas.Rectangle(0, 0, Width, Height);

    Canvas.Draw(0, 0, Bitmap);
  finally
    Bitmap.Free;
  end;

  inherited Paint;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Tela := TTela.Create(Self);
  Tela.Height := 400;
  Tela.Width := 500;
  Tela.Parent := Self;
  Tela.DoubleBuffered := True; // Required to avoid flickering on Windows
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Tela.Free;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Tela.Invalidade;
end;

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to