我创建了一个VCL表单应用程序,添加一个主菜单并从菜单模板中插入“MDI Frame Menu”。我运行程序并使用加速键。一切都按预期工作。
我现在添加一个工具栏,断开主菜单与表单的连接并将其链接到工具栏。我运行程序。现在只需按下相应的键即可激活菜单项,而无需按Alt键(例如,按“W”键可打开Windows菜单项。 如何让工具栏上的菜单显示为没有它的主菜单?
答案 0 :(得分:0)
我为我的问题创建了一个答案(可能有更简单和更优雅的答案)。在工具栏中创建TMainMenu的步骤与表单上的TMainMenu相同:
以下是代码段:
procedure TMainForm.DeleteHotKeysOfToolbarMenu(Sender: TObject);
var
m: integer;
begin
for m := 0 to Toolbar.ButtonCount-1 do
Toolbar.Buttons[m].Caption := StripHotKey(Toolbar.Buttons[m].Caption);
end;
procedure TMainForm.ActionListExecute(Action: TBasicAction; var Handled: Boolean);
begin
if Action.ActionComponent.ClassType = TMenuItem then
DeleteHotKeysOfToolbarMenu(Self);
end;
TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (ssAlt in Shift) or (Key = VK_F10) then
begin
Toolbar.Menu := nil;
Toolbar.Menu := MainMenu;
end;
if Key = VK_Escape then DeleteHotKeysOfToolbarMenu(Self);
end;