Changing font of TActionMainMenuBar when using Vcl styles

邮差的信 提交于 2019-12-09 18:36:18

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/13154517/changing-font-of-tactionmainmenubar-when-using-vcl-styles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!