How can I change the background color of my TTabSheets?
The standard Windows colour for a tab sheet is white. That standard came into being when XP themes were introduced. If a user switches back to Windows Classic then they will get a grey background. [You do mean grey rather than beige don't you? Beige would be truly vile!]
A panel inside a tab sheet can never be behind the page since it is inside the page. What is actually happening is that the panel is being drawn transparently so that the standard tab sheet colour prevails.
Use this unit in your Form at the interface:
unit MSCtrlsStyleHook;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.Themes,
Winapi.CommCtrl;
type
TTabSheet = class(Vcl.ComCtrls.TTabSheet)
private
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
end;
TPageControl = class(Vcl.ComCtrls.TPageControl)
private
procedure TCMAdjustRect(var Msg: TMessage); message TCM_ADJUSTRECT;
end;
implementation
{ TPageControl }
procedure TPageControl.TCMAdjustRect(var Msg: TMessage);
begin
inherited;
if Msg.WParam = 0 then
InflateRect(PRect(Msg.LParam)^, 3, 3)
else
InflateRect(PRect(Msg.LParam)^, -3, -3);
end;
{ TTabSheet }
procedure TTabSheet.WMEraseBkgnd(var Message: TWMEraseBkgnd);
var
LRect : TRect;
LCanvas: TCanvas;
begin
if (PageControl <> nil) and StyleServices.Enabled and
((PageControl.Style = tsTabs) or TStyleManager.IsCustomStyleActive) then
begin
//Get the bounds of the Tabsheet
GetWindowRect(Handle, LRect);
OffsetRect(LRect, -LRect.Left, -LRect.Top);
//create a TCanvas for erase the background, using the DC of the message
LCanvas := TCanvas.Create;
try
LCanvas.Handle := Message.DC;
LCanvas.Brush.Color:= $fafafa;// Color You need;
LCanvas.FillRect(LRect);
finally
LCanvas.Handle := 0;
LCanvas.Free;
end;
Message.Result := 1;
end
else
inherited;
end;
end.
Set the style property to tsFlatButtons
The background ~colour~ will revert to beautiful clBtnFace