DBCtrlGrid controls is a database, the data can be displayed in the form of a Panel Panel, but this control in double-buffering mode, once the loading data (dynamic drawing Panel), the whole screen controls will be flashing,
After tracking control source code, found procedure TDBCtrlGrid. WMEraseBkgnd (var Message: TMessage); The procedure TDBCtrlGrid. WMPaint (var Message: TWMPaint); These two functions is called, supposedly Windows redrawn constantly sending message, and then erase the background and mapping function has been called, is studied for a long time, did not find the root cause, according to online data, Windows are sending redraw message is generally due to invoke the begin paint paint lead to no end, but the Delphi built-in controls should not be made such a low-level mistakes... From Delphi7 to the latest XE10, is the question,
Below is the Demo code: put the database ado controls, then dbctrl1 data source with good, put a TDBText control display on the panel data, btn1Click write call SQL statements, placed a TImage picture again on the Form, so that the flicker problem can clear show,
unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ComCtrls dbcgrids, DB, ADODB, DBCtrls, ExtCtrls,
Pngimage;
Type
TForm1=class (TForm)
Ds1: TDataSource;
Qry1: TADOQuery;
Con1: TADOConnection;
Dbctrl1: TDBCtrlGrid;
Dbtxt1: TDBText;
Btn1: TButton;
Img1: TImage;
Procedure FormCreate (Sender: TObject);
Procedure btn1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
procedure TForm1.FormCreate(Sender: TObject);
The begin
SetWindowLong (Self. Handle, GWL_EXSTYLE GetWindowLong (Self. Handle, GWL_EXSTYLE) or WS_EX_COMPOSITED);//enabled double buffer
end;
Procedure TForm1. Btn1Click (Sender: TObject);
The begin
With qry1 do
The begin
Close;
SQL.Clear;
SQL. The Add (' select top 10 * from goods');
Open;
end;
end;
Running result: click btn1, dbctrl1 loaded the data and dynamically generated panel, when click the second panel, the whole screen controls have been flashing,
For each great god show... I really appreciate!
CodePudding user response:
I'm afraid that is not a DBCtrlGrid problem, but the problem of Windows, other languages have similar situation, WS_EX_COMPOSITED extension style force change the interface drawing order, can solve the problem of flicker, but have serious side effects, such as an empty form, under the classic theme of the icon of the client area click animation effects disappear, maximize window with a weight problem, particularly high CPU usage, and DWM is not compatible, you can also try to use FMX library interface component or set DoubleBuffered properties,Forms and DBCtrlGrid controls have DoubleBuffered attributes, can be set to True a try, it is a component level and different WS_EX_COMPOSITED double buffer solution, it is the first draw controls bitmap in memory, and then copy to prevent blinking window,