delphifontsvcl-stylesdelphi-xe3taction

Changing font of TActionMainMenuBar when using Vcl styles


Normally one could change the font of a TActionMainMenuBar or TMainMenu like this:

Screen.MenuFont.Name := 'Calibri';

When using Vcl styles this isn't possible any more if a StyleHook is registered for the component. I went into the Bitmap Style Designer (formerly known as Vcl Style Designer) and changed the font for the MenuItemTextNormal.

Problem is that changing the Font does nothing, I can only successfully change the Color of the text.

Clearly I'm missing something here, why can I change the Color but not the Font?


Solution

  • As you say changing the font of the MenuItemTextNormal element (or any other) in the style designer has no effect, this is because the Vcl Style Engine simply ignores the font size and name, and just use the font color defined in the vcl style file.

    As workaround you must define and register a new TActionBarStyleEx descendent and override the DrawText methods of the TCustomMenuItem and TCustomMenuButton classes, using the values of the Screen.MenuFont to draw the menu.

    I just added a new unit (Vcl.PlatformVclStylesActnCtrls) to the Vcl Styles Utils project which implements a new Action Bar Style which allows to customize the font and size of the TActionMainMenuBar component.

    To use it only add the Vcl.PlatformVclStylesActnCtrls unit to your project, change the values of the Screen.MenuFont font like

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

    and then set the Style of your TActionManager like so

      ActionManager1.Style:=PlatformVclStylesStyle;
    

    And the result will be

    enter image description here