Arnold
Arnold

Reputation: 4840

How enable application-wide color schemes?

I would like to apply color schemes to my application. This is done by making all components have their ParentColor set to true as well as ParentBackground and ParentFont. When I change the form color everything changes. There is an exception: toolbars and toolbuttons don't change. Is it possible to change them with the color of the form or must I implement this in a separate way?

The same applies to font colors, but that is a trifle more strange. When I change the font color of the form the font color of a groupbox caption does not change but the caption of label captions (also inside the groupbox) change allright.

When implementing some way to allow the user choose his own colors is this the way to go (change the form color, make all components have ParentColor set) or are there better ways to achieve this goal?

Upvotes: 2

Views: 735

Answers (1)

Simon
Simon

Reputation: 9425

One way to acheive this is to use interfaces.

It is a bit of (manual) work, but if you'd like to do it in a simple manner you could simply define an interface and ensure all your forms implement this interface.

for example:

type ITheme = interface
  procedure SetTheme(const AColor : TColor);
end;

then in each of you forms you could implement this interface.

So to change all of your forms' colors you simply need to call 1 function:

procedure SetGlobalTheme(const AColor : TColor);
var Intf : ITheme;
begin
  for i:=0 to screen.Formcount-1 do
  begin
    if Supports(Screen.Forms[i],ITheme,intf) then
      intf.SetTheme(AColor);
  end;
end;

Using this method you have full control of each components color, albeit with some more coding to be done. The alternative is to use David suggestion of VCL styles (if your IDE supports it)

Upvotes: 1

Related Questions