Question

I am experimenting with VCL Styles. This might be a silly question, but is it possible to have forms with different backgrounds when using a style? It seems that the form background (client area) is specified in the VCL style designer and it overrides the form's Color property.

How can I achieve forms with different background color? For example, I want my modal dialogs have a different background color than the main form.

Was it helpful?

Solution

Yes it is possible : if you are using Delphi XE3,XE4,XE5 : you only need to remove seClient from the StyleElements property of your form :

 Form3.StyleElements := [seFont, seBorder];

if you are using delphi xe2: you should override the TFormStyleHook class ,and catch the WM_ERASEBKGND message , and return without processing the default message :

type
  TFormStyleHookEx = class(TFormStyleHook)
    procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND;
  end;
{ TFormStyleHookEx }

procedure TFormStyleHookEx.WMEraseBkgnd(var Message: TMessage);
begin
  Message.Result := 1;
end;

initialization

TStyleEngine.RegisterStyleHook(TForm3, TFormStyleHookEx);

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top