程序加载期间添加的菜单项的Vcl样式问题 [英] Vcl Styles issue for menu items added during program load

查看:64
本文介绍了程序加载期间添加的菜单项的Vcl样式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Delphi 10.4.2程序(32位),其中在程序加载期间添加了菜单项(Application.OnActivate事件,编码为仅运行一次).没有vcl样式,新项目将正确显示,但是当应用样式(例如屏幕截图中非常漂亮的Iceberg Classico)时,显示将不正确.菜单选项在那里,可以单击;但是没有绘制文字和图标.

I have a Delphi 10.4.2 program (32-bit) where menu items are added during program load (the Application.OnActivate event, coded to run only once). Without a vcl style the new items are displayed correctly, however when a style is applied (such as the very nice Iceberg Classico in the screenshot) the display is not correct. The menu options are there, and can be clicked on; but the text and the icon are not drawn.

有没有工作回合?我认为这是因为在应用样式后 后添加了这些特定的菜单选项.有没有一种方法可以刷新样式?或者创建菜单项时我是否缺少设置属性?

Any workrounds? I'm assuming that it’s because those particular menu options are added after the style is applied. Is there a way to refresh the style?, or am I missing a setup property when creating the menu items?

谢谢.

编辑:是的,文件"菜单和子菜单项正确显示.创建新菜单和项目(简化)的代码为:

Edit: Yes, the 'File' menu and sub menu items are displayed correctly. Code that creates the new menu and items (simplified) is:

procedure TDbHelper.CreateHelpMenu;
// Called by OnApplicationActivated event, and run just once 
var
   aMenu: TMainMenu;
   mnHelp, mnItem: TMenuItem;
   idx: Integer;
begin
   aMenu := Application.MainForm.Menu;
   // create new menu
   mnHelp         := aMenu.CreateMenuItem;
   mnHelp.Name    := 'WISHelp1';               
   mnHelp.Caption := 'WIS Help';
   aMenu.Items.Add(mnHelp);
   // now the submenu items
   for idx := 0 to HelpLinks.Count - 1 do
   begin
      mnItem := TMenuItem.Create(mnHelp);
      mnItem.Name := HelpLinks[idx].Key;
      mnItem.Caption := HelpLinks[idx].Text;
      mnItem.ImageIndex := HelpLinks[idx].ImageIndex;                            
      mnItem.OnClick := WISHelpItemClick;
      mnHelp.Add(mnItem);
   end;
end;

推荐答案

最后决定关闭菜单的vcl样式.我在另一个问题上遵循了RRUZ的建议,并在dpr源中添加了一行,使其变为:

Finally decided to switch off the vcl styles for the menus. I followed the advice of RRUZ on another question and added a line to the dpr source so that it became:

  Application.Initialize;
  TStyleManager.TrySetStyle('Iceberg Classico');
  with TStyleManager do SystemHooks := SystemHooks - [shMenus];
  Application.Title :=  'blah, blah, etc'

菜单项重新出现,并且看起来不错:

The menu items have re-appeared, and they look fine:

感谢SilverWarior的意见和建议.

Thank you to SilverWarior for their input and suggestions.

这篇关于程序加载期间添加的菜单项的Vcl样式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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