The Road to Delphi

Delphi – Free Pascal – Oxygene

How customize the fonts of a TActionMainMenuBar and TPopupActionBar with the VCL Styles Enabled

2 Comments

This week I received two emails from different Delphi developers asking about : How customize the fonts of a TActionMainMenuBar and TPopupActionBar with the Vcl Styles Enabled? Also a question about the same topic was asked in StackOverflow.

This post shows how this task can be done.

In order to change the font and size of a TActionMainMenuBar and a TPopupActionBar in a VCL application you must use the Screen.MenuFont property like so.

  Screen.MenuFont.Name := 'Impact';
  Screen.MenuFont.Size := 12;

But if the Vcl Styles are enabled these changes are not reflected (This is because the Vcl Styles uses the fonts defined in style file).

Now if you want change the font type or font size of the Vcl Styles elements related to the menus like MenuItemTextNormal, MenuItemTextHot and so on, you will use the Style Designer and set font values which you want.

But unfortunately this will not work either, I mean even if you edit the fonts of the Vcl Style file, the changes are not reflected in the Menus components (or others controls). The reason for this is that the Vcl Styles Engine ignores the fonts types and font size defined in the style file. and just use the font color value to draw the text of the controls.

Note : The font used by the Vcl Styles is Tahoma and the Size is 8.

So what is the solution for customize the font of a TActionMainMenuBar component? A possible workaround is create a new Action Bar Style and also create a new TCustomMenuItem and TCustomMenuButton to override the DrawText method and draw your self the menu text using the Screen.MenuFont values, the good news are which since now, you can find a implementation of a new Action Bar Style in the <a href="https://github.com/RRUZ/vcl-styles-utils/blob/master/Common/Vcl.PlatformVclStylesActnCtrls.pas unit (which is part of the VCL Styles Utils project) which allows you to modify the font of the TActionMainMenuBar and TPopupActionBar components.

So to use this new Action Bar Style, just add the Vcl.PlatformVclStylesActnCtrls unit to your project and then assign the new style to your Action Manager like so :

  ActionManager1.Style:=PlatformVclStylesStyle;

And now when you run your app the TActionMainMenuBar and TPopupActionBar will use the font defined in the Screen.MenuFont property.

Author: Rodrigo

Just another Delphi guy.

2 thoughts on “How customize the fonts of a TActionMainMenuBar and TPopupActionBar with the VCL Styles Enabled

  1. Neato’ !

    The first one defines the phrase “bold text”.

  2. Pingback: Sip from the Firehose : FireMonkey and VCL Styles - articles, blogs, videos, docs and examples

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 )

Google+ photo

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

Connecting to %s