Changing the TActionMainMenuBar Font When Using Vcl Styles

You can usually change the font TActionMainMenuBar or TMainMenu as follows:

Screen.MenuFont.Name := 'Calibri'; 

When using Vcl styles, this is not possible 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 MenuItemTextNormal .

The problem is that changing the font does nothing, I can only successfully change the color of the text.

It’s clear that I missed something, why can I change the color, but not the font?

+4
source share
1 answer

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 a workaround, you should define and register a new TActionBarStyleEx descendent and override the DrawText methods of the TCustomMenuItem and TCustomMenuButton classes using Screen.MenuFont values ​​to draw the menu.

I just added a new block ( Vcl.PlatformVclStylesActnCtrls ) to Vcl Styles Utils , which implements a new Action Bar style that allows you to customize the font and size of the TActionMainMenuBar component.

To use it, add only the Vcl.PlatformVclStylesActnCtrls module to the project, change the values ​​of the Screen.MenuFont font, for example

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

and then set your TActionManager style this way

  ActionManager1.Style:=PlatformVclStylesStyle; 

And the result will be

enter image description here

+5
source

Source: https://habr.com/ru/post/1443185/


All Articles