How to apply VCL Style to Delphi Open Dialog, Save Dialog, Print Dialog, Font Dialog, Menus and TTaskDialog ?

We can apply styles to a Delphi Application by using provided VCL styles from Project -> Options -> Appearance -> Styles option. But problem with VCL style is that, it does not support for Menus, Popup Menus, System Menus, TTaskDialog Component and Common Dialogs like Open Dialog, Save Dialog, Print dialog, Font Dialog etc. So whit out above dialogs and menus a Delphi application is not completely VCL style applied.

So here in this blog I will explain how to apply VCL style to Menus, Popup Menus, System Menus, TTaskDialog Component and Common Dialogs like Open Dialog, Save Dialog, Print dialog, Font Dialog etc.

Rodrigo Ruz a Delphi MVP from Chile has provided a solution for that. He has relased ‘VCL Styles Utils’ units and classes for the above purpose. 

VCL Styles Utils
The VCL Styles Utils is a Delphi library which extend the RAD Studio VCL Styles, adding unique features like the support for Classic and New Common dialogs, Task Dialogs, Styling of popup and shell menus, Non client area components and much more.

Download
We can download VCL Styles Utils from folloring GitHub link and install the units on local.


Installation
1. Unzip or checkout the files of the library in a writable folder.

2. Under Tools, Environment Options, Library, add the directory where the VCL Styles Utils library have been installed 
Example : C:\Delphi\Libs\vcl-styles-utils\Common to the Win32 and Win64 library path.

Note : If you want to use the Vcl.Styles.Hooks unit you must also include the Delphi Detours Library files in your lib/search path 
Example : C:\Delphi\Libs\vcl-styles-utils\Common\delphi-detours-library

Features
Works in Delphi XE2-XE8, 10 Seattle, 10.1 Berlin, 10.2 Tokyo, 10.3 Rio.

Now lets check with an example.
Here I have created a sample Delphi application having single form with common controls like Button, Edit, CheckBox, RadioButton and Menus.  And on some Buttons click I am also opening Open dialog, save Dialog, Print dialog and others. I have applied VCL style to my application by writing following code in Dpr file.

program Project1;
uses
  Vcl.Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Vcl.Themes,
  Vcl.Styles;
{$R *.res}
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Amethyst Kamri');  //applies VCL style//
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.


Here you can see that style is applied to above form in my application but when I clicked on menus or  buttons to open required dialogs, I found that style is not applied to those dialogs and menus.

unit Unit1;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin,
  Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.Menus,
  Vcl.Styles.DateTimePickers, Vcl.StdActns, Vcl.ExtActns, System.Actions,
  Vcl.ActnList, Vcl.PlatformDefaultStyleActnCtrls, Vcl.ActnMan, Vcl.ActnMenus,
  Vcl.ToolWin, Vcl.ActnCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Edit1: TEdit;
    ComboBox1: TComboBox;
    Button7: TButton;
    CheckBox1: TCheckBox;
    RadioButton1: TRadioButton;
    RadioGroup1: TRadioGroup;
    ProgressBar1: TProgressBar;
    SpinEdit1: TSpinEdit;
    MainMenu1: TMainMenu;
    FILE1: TMenuItem;
    NEW1: TMenuItem;
    SAVE1: TMenuItem;
    CLOSE1: TMenuItem;
    EDIT2: TMenuItem;
    COPY1: TMenuItem;
    PASTE1: TMenuItem;
    PopupMenu1: TPopupMenu;
    POP11: TMenuItem;
    POP21: TMenuItem;
    POP31: TMenuItem;
    DateTimePicker1: TDateTimePicker;
    MonthCalendar1: TMonthCalendar;
    ActionManager1: TActionManager;
    EditCut1: TEditCut;
    EditCopy1: TEditCopy;
    EditPaste1: TEditPaste;
    HelpContents1: THelpContents;
    HelpTopicSearch1: THelpTopicSearch;
    HelpOnHelp1: THelpOnHelp;
    FileOpen1: TFileOpen;
    FileOpenWith1: TFileOpenWith;
    FileSaveAs1: TFileSaveAs;
    FilePrintSetup1: TFilePrintSetup;
    FilePageSetup1: TFilePageSetup;
    FileRun1: TFileRun;
    FileExit1: TFileExit;
    ActionToolBar1: TActionToolBar;
    ActionMainMenuBar1: TActionMainMenuBar;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TOpenDialog.Create(self) do
    Execute();
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  with TSaveDialog.Create(self) do
    Execute();

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  with TPrintDialog.Create(self) do
    Execute();

end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  with TFontDialog.Create(self) do
    Execute();

end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  with TColorDialog.Create(self) do
    Execute();

end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  with TFindDialog.Create(self) do
    Execute();
end;

end.

Lets see..

Style is not applied to main menu items.


Style is not applied to PopUp menu items.


Style is not applied to System menu


Style is not applied to Open Dialog


Style is not applied to Save Dialog


Style is not applied to Print Dialog


Style is not applied to Font Dialog


Style is not applied to Color Dialog


Style is not applied to find Dialog


Style is not applied to TTaskdialog component


Solution - Apply 'VCL Style Utils'

So to apply ‘VCL Style Utils’ in a Delphi project we need to add the following ‘VCL Style Utils’units to a Delphi Project file i.e in .dpr file.

  Vcl.Styles.Utils.Graphics ,
  Vcl.Styles.Utils.Menus ,
  Vcl.Styles.Utils.Forms ,
  Vcl.Styles.Utils.StdCtrls ,
  Vcl.Styles.Utils.ComCtrls ,
  Vcl.Styles.Utils.ScreenTips ,
  Vcl.Styles.Utils.SysControls,
  Vcl.Styles.Utils.SysStyleHook;

like as follow

program Project1;
uses
  Vcl.Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Vcl.Themes,
  Vcl.Styles,
  Vcl.Styles.Utils.Graphics ,
  Vcl.Styles.Utils.Menus ,
  Vcl.Styles.Utils.Forms ,
  Vcl.Styles.Utils.StdCtrls ,
  Vcl.Styles.Utils.ComCtrls ,
  Vcl.Styles.Utils.ScreenTips ,
  Vcl.Styles.Utils.SysControls,
  Vcl.Styles.Utils.SysStyleHook;
{$R *.res}
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Amethyst Kamri');  //applies VCL style//
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

And after added the unit for Delphi project file and now we can see VCL Style is applied to Dialogs, Menus and TTaskDialog components also.

Style is applied to Main Menu items


Style is applied to Popup Menu items


Style is applied to System Menu items


Style is applied to Open dialog.


Style is applied to Save dialog.


Style is applied to Print dialog.


Style is applied to Font dialog.


Style is applied to Color dialog.


Style is applied to Find dialog.


Style is applied to TTaskdialog dialog.



Comments

  1. Thanks! Was looking for something like this and appreciate your sharing!

    ReplyDelete

Post a Comment

Popular posts from this blog

MS Excel Automation in Delphi

ShellExecute in Delphi

Drawing Shapes in Delphi