The Road to Delphi – a Blog about programming

Delphi – Lazarus – Delphi Prism

VCL Style Utils

The VCL Styles Utils is a collection of classes and style hooks, which extend and add new features to the VCL Styles (introduced in Delphi XE2).

Some of the features of this project are

Introduces the Vcl.Styles.Ext unit which extend the TStyleManager Delphi class adding new properties and methods to list, remove and reload the vcl styles. The extension of the TStyleManager class was made using class helpers, because that only you must add the Vcl.Styles.Ext unit to your project to start to use it.

Example to remove a vcl style

  TStyleManager.RemoveStyle('Carbon');

This unit also a define a new class called TCustomStyleExt that descends of the TCustomStyle and allow you to access to the RAW data of the vcl styles like bitmaps, fonts and colors.

For example you can modify the vcl styles colors in this way

  TCustomStyleExt(TStyleManager.ActiveStyle).SetStyleColor(scEdit, clRed);
  TCustomStyleExt(TStyleManager.Style[StyleName]).SetSystemColor(clBtnFace,clLime);
  TCustomStyleExt(TStyleManager.Style[StyleName]).SetStyleColor(scBorder, clBlue);
  TCustomStyleExt(TStyleManager.Style[StyleName]).SetStyleFontColor(sfButtonTextNormal, clYellow);

The Vcl.Styles.Utils unit contain classes to modify existing styles using color operations like Blend, HSL and RGB.

Check this form with the Carbon style applied.

//This code shows how you can add a Overlay blend effect to an existing vcl style
//and then apply the changes in run-time.
procedure TFrmMain.FormCreate(Sender: TObject);
var
  VclStylesUtils : TVclStylesUtils;
  Filters        : TObjectList;
begin
  //create the instance to the  TVclStylesUtils using the carbon vcl style
  VclStylesUtils:=TVclStylesUtils.Create('Carbon');
  //create the filter list to apply
  Filters:=TObjectList.Create;
  try
    //create a TBitmap32BlendOverlay filter and add to the list
    Filters.Add(TBitmap32BlendOverlay.Create(clYellow));
    //set the elements to be affected
    VclStylesUtils.Elements:=VclStylesUtils.Elements+ [vseBitmaps ,vseSysColors, vseStyleColors];
    //set the filters
    VclStylesUtils.SetFilters(Filters);
    //Apply the changes to the style
    VclStylesUtils.ApplyChanges;
    //reload the modified style
    TStyleManager.ReloadStyle('Carbon');
  finally
    VclStylesUtils.Free;
    Filters.Free;
  end;
end;

And this is the result after of apply the above code

Add a new style hook to enable the vcl styles in the TWebBrowser component, more info can be found in this article http://theroadtodelphi.wordpress.com/2012/03/20/delphi-vcl-styles-and-twebbrowser-source-code-released/

Add a new style hook to customize the background and non client area of a form, more info can be found in this article http://theroadtodelphi.wordpress.com/2012/03/26/vcl-styles-adding-background-images-and-colors-to-delphi-forms/

Source Code

The full source code of this project is available in the google code project hosting site under the Mozilla Public License 1.1

4 thoughts on “VCL Style Utils

  1. Is there a possibility to apply a style only to one controle, like a button and leave the rest of the form or whole application in Windows VCL Style?
    Thanks, nice work btw.

  2. Great Job!!!

    I am using FastReport and Delphi XE3, both are working perfectly.
    Now there is a problem, when I enable VCL Styles FastReport is not getting themed properly, it might be because of the TWebBrowser component. Also, there is an issue with the toolbar, its borders are transparent.

    See the screenshot
    http://i45.tinypic.com/2hmkf87.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 401 other followers