1

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.

jpfollenius
  • 16,456
  • 10
  • 90
  • 156
  • 1
    possible duplicate of [How to color the background of a TComboBox with VCL styles enabled](http://stackoverflow.com/questions/16538890/how-to-color-the-background-of-a-tcombobox-with-vcl-styles-enabled) – Arioch 'The Oct 28 '13 at 10:58
  • Also useful links are at http://stackoverflow.com/questions/9906312/ – Arioch 'The Oct 28 '13 at 11:00
  • The link @Arioch'The provided contains the solution, you just need to adapt a few things: ` TFromStyleHookExt= class(TFormStyleHook)` change TWinControlClass(Control). to TForm(Control). adapt initialization TStyleManager.Engine.RegisterStyleHook(TForm_XY, TFromStyleHookExt); and change WndProc. – bummi Oct 28 '13 at 11:46

1 Answers1

7

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

S.MAHDI
  • 1,022
  • 8
  • 15
  • 1
    He is on XE2, StyleElements are not known here. – bummi Oct 28 '13 at 11:43
  • nice and concise, but unfortunately IMHO the question is still a duplicate. – bummi Oct 28 '13 at 12:05
  • @bummi the answer might be contained in the other thread but since it is specifically about `TForm` I think it does provide value to others. – jpfollenius Oct 28 '13 at 12:13
  • @Smasher more convinced than skeptical (70/30) I'll retract my close vote. – bummi Oct 28 '13 at 13:35
  • Would not retract: the links is a useful one and increases the connectivity. And i cannot remove the voice and then re-insert the link before @bummi's comment – Arioch 'The Oct 28 '13 at 13:39