Automatically start a process with administrative rights under Windows Vista »
« VB6 vs Vista - registering ActiveX components

Remove flickering during resizing and correct controls rendering under Vista

In our applications, we often feel the need to avoid controls flickering during the parent controls resizing, to make them appear more professional.

Delphi 2007, supports all the advanced and hot features of Microsoft Windows Vista Aero (natively and without adding a single line of code), but some VCL controls are not rendered correctly if placed in the transparent window area.

Both these issues are easily resolved by code-setting to TRUE the "DoubleBuffered" property of the parent control, property made available from Delphi 2005. In fact, the issues in object take place because their DoubleBuffered property is False by default and furthermore such property is not reachable from the ObjectInspector, because it’s not marked as Published.

Because of this limitation, it would be much easier an automatic way to set to True all the DoubleBuffered properties of all controls that support it, without having to manually write a bunch of code lines for each control of our form (and for the form itself, do not forget!).

The Delphi team has run in your help, writing the following code that solve all the mentioned issues:

procedure TFormMain.DoubleBufferAll();
var
  i: Integer;
begin
  try
    Self.DoubleBuffered := True;
    for i := 0 to Self.ComponentCount - 1 do begin
      if Self.Components[i] is TWinControl then begin
        TWinControl(Self.Components[i]).DoubleBuffered := True;
      end;
    end;
  except
    on E:Exception do begin
      //
    end;
  end;
end;

Just call this new method (declared as private in the Private section of TFormMain class) in the OnCreate method of the form, and you are done!

A little side effect to take into consideration: with Turbo Delphi 2006 under WinXP with themes activated, the TPageControl and TTabControl are not rendered correctly: the background does not appear as gradient. The solution is simply to set their DoubleBuffered property to False.

Monday, January 28th, 2008 : Software development : 3 Comments

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

    3 Responses to “Remove flickering during resizing and correct controls rendering under Vista”

  1. Baby Says:

    There is so amazing for us! Thanx!


  2. Erarriano Says:

    5 февраля компанией «Полисет-СБ» будет представлена комплексная система безопасности под названием «Экспресс». Данная демонстрация пройдет в Москве в Выставочном комплексе «Крокус Сити», ведь именно здесь в это время и будет проводиться выставка «Технологии безопасности», тематике которой «Экспресс» полностью соответствует.


  3. gofovelomow Says:

    I’m frequently searching for new infos in the world wide web about this topic. Thx.


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>