Tuning VCL Styles for Forms and Controls

By: Tim DelChiaro

Abstract: Blog post from Alexey Sharagin

This is a repost of a blog post from Alexey Sharagin. Click the blog post title below to see the original post, comments, or to visit Alexey's Styles for VCL and FireMonkey blog to see additional posts.

Tuning VCL Styles for Forms and Controls

    StyleElements Property

Delphi XE3 introduces the possibility of flexible tuning of styles to different elements of VCL controls: font colors, client parts, borders, and scrollbars. For this purpose, Delphi XE3 introduces the Vcl.Controls.Controls.StyleElements property of the TStyleElements type:
TStyleElements = set of (seFont, seClient, seBorder); .

In different controls this property can work differently depending upon complexity of the control and the logic of its functionality. This property can be used as in IDE’s design mode so during an application execution. By default, all seFont, seClient, and seBorder parameters are used:

The following example demonstrates how you can use TStyleElements with a Vcl.StdCtrls.TMemo control:

You can customize style elements from the code. For example:
TForm.StyleElements = TForm.StyleElements - [seBorder];
this line turns OFF implementation of a style to the border of the particular form.

    Global Turning ON/OFF of Stylization for Form Border

Delphi XE3 introduces the Vcl.Themes.TStyleManager.FormBorderStyle property of the
TFormBorderStyle = (fbsCurrentStyle, fbsSystemStyle); type.

You can use FormBorderStyle to globally switch between the current or system border for all forms in an application. fbsCurrentStyle defines to use the border from the current style; fbsSystemStyle defines to use the system border (fbsCurrentStyle is the default).
You can use this property adding appropriate code into the source code of a project file or into the source code of an application. For example, to switch OFF using of the form border from the current style to all forms on an application, you can add the
TStyleManager.FormBorderStyle := fbsSystemStyle;
line into the code of the project file.

For example like this:

Application.MainFormOnTaskbar := True;

TStyleManager.FormBorderStyle :=  fbsSystemStyle;

Application.CreateForm(TForm1, Form1);

    Animation Effects on Buttons

Delphi XE3 introduces the Boolean Vcl.Themes.TStyleManager.AnimationOnControls property. You can use this property to activate animation effects for TButton and TBitBtn buttons. The default is False. Setting AnimationOnControls to True activates the fading effect to a button, when some style is active. For example, you can turn ON/OFF fading effects by adding this property into a project file code or by adding this property into an application code. To produce fading effects, VCL uses OS system functions. Therefore, animation itself executes using OS functions and it is accessible beginning from Windows Vista.

Example of including the AnimationOnControls property into a project file code:


TStyleManager.AnimationOnControls := True

Application.CreateForm(TForm1, Form1);

    Cooperation and Synchronization of TRibbon Styles and VCL Styles

In Delphi XE3, you can create applications in the TRibbon style. Three special Luna, Obsidian and Silver styles are provided for this. Delphi XE3 introduces the cooperation between TRibbon and TForm when a TRibbon style is active. (TRibbon automatically switches OFF seBorder in TForm.StyleElements and takes responsibility for drawing of nonclient area.) For synchronization link all 3 Ribbon type Luna, Obsidian and Silver styles to an application and loads them concurrently with switching an application GUI to Ribbon style.

Adding Ribbon type styles in Project Options:

Example of concurrent switching of styles:

procedure TForm1.frmRibbonDemoMainRibbonStyleLunaActnExecute(Sender: TObject);
Ribbon1.Style := RibbonLunaStyle;

Server Response from: ETNASC03