The screenshot was taken during window activation. As it can be seen some controls are being painted with black background first. Those are TCheckBox, TButton, TStringGrid. I would like the black regions under the controls to be in color of the form which is clBtnFace. How could I fix this?
Edit: It happens in VCL, Delphi 10.3.3, Windows 10. By window activation I meant that the application is already running and was minimised to taskbar. There are just a lot of controls put onto form. There are 7 TPanels, around 60 TEdits as can be seen, next to them there are around 60 TLabels which are not yet painted and the rest with black background are few TCheckBoxes, TButtons and one empty TStringGrid.
Tested with empty form, put one TPanel and on top of it 300 TEdits and behaviour the same. So it is by design that some of the controls are painted first with black background. So how could I change that default background color to something else?
Edit2: Tested with 400 TPanels on form. These are painted as expected without setting of the Rect under TPanel to black.
Edit3: Unfortunately with 1000 TPanels on form repainting is enough slow so I am able to observe the black background.
Here is the code with which I test controls:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.ExtCtrls, Vcl.StdCtrls;
const
ControlsNum=800;
Columns=40;
type
TControlTestList=array of TButton;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
var CList:TControlTestList;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
W,H:integer;
begin
Self.Width:=1400;
Self.Height:=800;
W:=Self.ClientWidth div Columns;
H:=Self.ClientHeight div (ControlsNum div Columns);
SetLength(CList,ControlsNum);
for i:=0 to ControlsNum-1 do
begin
CList[i]:=TButton.Create(Self);
with (CList[i] as TButton) do
begin
Parent:=Self;
Top:=H*(i div Columns);
Left:=W*(i mod Columns);
Width:=W;
Height:=H;
Caption:=IntToStr(i);
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
i:integer;
begin
for i:=0 to Length(CList)-1 do FreeAndNil(CList[i]);
SetLength(CList,0);
end;
end.
Edit4: On Windows 10: The black background under controls doesn't appear during any type of form resize. Only when minimalistation of window and bringing it back is done. On Windows 8.1: Black background also appears when form is resized.