How to reduce DevExpress VCL Form Flickering

岁酱吖の 提交于 2019-12-24 21:38:45

问题


I am having another project with DevExpress VCL Component with skin support. On a TcxPageControl I have placed two TPanels and its caption color will be changed depending on one TTimer. The panel caption color is changing always with a flicker but it changes smoothly in a normal TPageControl. Here is my sample code:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, dxSkinsCore, dxSkinVisualStudio2013Dark,
  dxSkinscxPCPainter, dxBarBuiltInMenu, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, Vcl.Menus, cxClasses, cxContainer, cxEdit, dxBevel,
  Vcl.StdCtrls, cxButtons, dxSkinsForm, cxPC, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    cxTabSheet4: TcxTabSheet;
    cxTabSheet5: TcxTabSheet;
    dxSkinController1: TdxSkinController;
    cxButton1: TcxButton;
    Panel1: TPanel;
    Panel2: TPanel;
    Timer1: TTimer;
    Timer2: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    FoldedClientHeight: Integer;
    ContractedClientHeight: Boolean;
  public
    { Public declarations }
    procedure WMNCRButtonDown(var Msg: TWMNCRButtonDown); message WM_NCRBUTTONDOWN;
    procedure WMNCLButtonDblClk(var Msg: TWMNCLButtonDblClk); message WM_NCLBUTTONDBLCLK;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMNCRButtonDown(var Msg: TWMNCRButtonDown);
begin
  if Msg.HitTest = HTCAPTION then
    begin
      Form1.Timer2.Enabled := true;
    end
  else
    begin
      inherited;
    end;
end;

procedure TForm1.WMNCLButtonDblClk(var Msg: TWMNCLButtonDblClk);
begin
  if Msg.HitTest = HTCAPTION then
    begin
      Form1.Timer2.Enabled := true;
    end
  else
    begin
      inherited;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer2.Enabled := false;
  Timer2.Interval := 1;
  FoldedClientHeight := ClientHeight;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
const
  IncrementalFactor = 5;
  DecrementalFactor = 5;
var
  RPanel1, GPanel1, BPanel1, RPanel2, GPanel2, BPanel2: Integer;
begin

  RPanel1 := GetRValue(ColorToRGB(Panel1.Font.Color));
  GPanel1 := GetGValue(ColorToRGB(Panel1.Font.Color));
  BPanel1 := GetBValue(ColorToRGB(Panel1.Font.Color));
  if (RPanel1 = 255) and (GPanel1 = 000) and (BPanel1 < 255) then
    begin
      BPanel1 := BPanel1 + IncrementalFactor;
    end
  else if (RPanel1 > 000) and (GPanel1 = 000) and (BPanel1 = 255) then
    begin
      RPanel1 := RPanel1 - DecrementalFactor;
    end
  else if (RPanel1 = 000) and (GPanel1 < 255) and (BPanel1 = 255) then
    begin
      GPanel1 := GPanel1 + IncrementalFactor;
    end
  else if (RPanel1 = 000) and (GPanel1 = 255) and (BPanel1 > 000) then
    begin
      BPanel1 := BPanel1 - DecrementalFactor;
    end
  else if (RPanel1 < 255) and (GPanel1 = 255) and (BPanel1 = 000) then
    begin
      RPanel1 := RPanel1 + IncrementalFactor;
    end
  else if (RPanel1 = 255) and (GPanel1 > 000) and (BPanel1 = 000) then
    begin
      GPanel1 := GPanel1 - DecrementalFactor;
    end
  else
    begin
      Timer1.Enabled := false;
    end;
  Panel1.Font.Color := RGB(RPanel1, GPanel1, BPanel1);

  RPanel2 := GetRValue(ColorToRGB(Panel2.Font.Color));
  GPanel2 := GetGValue(ColorToRGB(Panel2.Font.Color));
  BPanel2 := GetBValue(ColorToRGB(Panel2.Font.Color));
  if (RPanel2 = 255) and (GPanel2 = 000) and (BPanel2 < 255) then
    begin
      BPanel2 := BPanel2 + IncrementalFactor;
    end
  else if (RPanel2 > 000) and (GPanel2 = 000) and (BPanel2 = 255) then
    begin
      RPanel2 := RPanel2 - DecrementalFactor;
    end
  else if (RPanel2 = 000) and (GPanel2 < 255) and (BPanel2 = 255) then
    begin
      GPanel2 := GPanel2 + IncrementalFactor;
    end
  else if (RPanel2 = 000) and (GPanel2 = 255) and (BPanel2 > 000) then
    begin
      BPanel2 := BPanel2 - DecrementalFactor;
    end
  else if (RPanel2 < 255) and (GPanel2 = 255) and (BPanel2 = 000) then
    begin
      RPanel2 := RPanel2 + IncrementalFactor;
    end
  else if (RPanel2 = 255) and (GPanel2 > 000) and (BPanel2 = 000) then
    begin
      GPanel2 := GPanel2 - DecrementalFactor;
    end
  else
    begin
      Timer1.Enabled := false;
    end;
  Panel2.Font.Color := RGB(RPanel2, GPanel2, BPanel2);
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var
  MinClientHeight: Integer;
begin
  MinClientHeight := GetSystemMetrics(SM_CYMIN) - (GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYFIXEDFRAME));

  if (ContractedClientHeight = true) then
    begin
      if ClientHeight < FoldedClientHeight then
        begin
          ClientHeight := ClientHeight + 25;
        end
      else
        begin
          ContractedClientHeight := false;
          Timer2.Enabled := false;
        end;
    end
  else if (ContractedClientHeight = false) then
    begin
      if ClientHeight > MinClientHeight then
        begin
          ClientHeight := ClientHeight - 25;
        end
      else
        begin
          ContractedClientHeight := true;
          Timer2.Enabled := false;
        end;
    end;
end;

end.

And I am also defined the form rolling using another TTimer. It is also creates form flickering. I thing this is due to Double Buffer because it is not available in DevExpress VCL Components.

How fix all the issues? How to add Double Buffering in DevExpress VCL Components?

来源:https://stackoverflow.com/questions/35778037/how-to-reduce-devexpress-vcl-form-flickering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!