When I dock a TForm
to a TTabSheet
the form has a gray background color. The tab sheet on the other hand has a white background color.
It gets more complicated when theming is disabled (e.g. classic Windows theme).
With the current code the grey form has a white border which is pretty ugly.
So how do I set the form background color to the tab sheet background color? In case this doesn't work: How do I set the tab sheet background color to the forms background color?
It should work with runtime themes enabled and runtime themes disabled.
program Project1;
uses
Graphics,
Controls,
Forms,
ComCtrls;
{$R *.res}
var
Main : TForm;
Sub : TForm;
PageControl : TPageControl;
TabSheet : TTabSheet;
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm, Main);
Application.CreateForm(TForm, Sub);
PageControl := TPageControl.Create(Main);
PageControl.Parent := Main;
PageControl.Align := alClient;
TabSheet := TTabSheet.Create(Main);
TabSheet.PageControl := PageControl;
Sub.Dock(TabSheet, TabSheet.ClientRect);
Sub.Align := alClient;
Sub.Show;
// Sub.Color := clWhite; // TabSheet.Color;
Application.Run;
end.
I found this workaround
type
TWinControlAccess = class(TWinControl)
end;
procedure TMainForm.CreateEmbedded(FormClass: TFormClass; Parent: TWinControl);
var
form: TForm;
begin
form := FormClass.Create(Self);
form.Align := alClient;
form.BorderIcons := [];
form.BorderStyle := bsNone;
form.Parent := Parent;
TWinControlAccess(form).ParentBackground := True; // <<<-
form.Show;
end;