使用Vcl样式时更改TActionMainMenuBar的字体 [英] Changing font of TActionMainMenuBar when using Vcl styles

查看:177
本文介绍了使用Vcl样式时更改TActionMainMenuBar的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,可以这样更改TActionMainMenuBar或TMainMenu的字体:

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

Screen.MenuFont.Name := 'Calibri';

使用Vcl样式时,如果为组件注册了StyleHook,则将无法再进行此操作. 我进入了位图样式设计器(以前称为Vcl样式设计器),并更改了 MenuItemTextNormal 的字体.

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?

推荐答案

正如您所说,在样式设计器中更改 MenuItemTextNormal 元素(或任何其他元素)的字体无效,这是因为Vcl样式引擎仅忽略字体大小和名称,而仅使用vcl样式文件中定义的字体颜色.

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.

作为解决方法,您必须定义并注册一个新的 TActionBarStyleEx 后裔,并使用Screen.MenuFont的值绘制菜单,并重写TCustomMenuItem和TCustomMenuButton类的DrawText方法.

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.

我刚刚添加了一个新单元( Vcl样式实用程序项目,该项目实现了新的操作栏样式,该样式允许自定义 TActionMainMenuBar 组件.

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.

要使用它,只需将Vcl.PlatformVclStylesActnCtrls单元添加到您的项目中,请更改Screen.MenuFont字体的值,如

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;

然后像这样设置TActionManager的样式

and then set the Style of your TActionManager like so

  ActionManager1.Style:=PlatformVclStylesStyle;

结果将是

这篇关于使用Vcl样式时更改TActionMainMenuBar的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆