gpt4 book ai didi

delphi - 解决 TActionMainMenuBar 绘画错误,其中项目未取消选择

转载 作者:行者123 更新时间:2023-12-03 15:14:11 24 4
gpt4 key购买 nike

TActionMainMenuBar 在绘制没有子项的根元素时存在错误。

使用Delphi XE2/w7-32位**

如何重现:
使用 TActionMainMenuBar 构建菜单,向其中添加一些操作:

 file  | options | help
- New
- Open
- Save
-Exit

为所有操作分配一个空方法

procedure TfrmMain.ActionExecute(Sender: TObject); 
begin
//
end;

现在运行应用程序并尝试单击选项或帮助元素。
现在单击表单,但菜单元素仍然被按下!

存在任何解决方法吗?

upd:看截图,菜单元素已按下,但鼠标光标不在菜单上,并且自动检查为假,检查也为假。
enter image description here
这里表单上没有任何颜色图,管理器样式是平台默认的

最佳答案

这是我的解决方法:
像这样创建自定义类:


type
TFastThemedButton = class(TThemedMenuButton)
protected
procedure DrawBackground(var PaintRect: TRect); override;
end;

...


procedure TFastThemedButton.DrawBackground(var PaintRect: TRect);
const
MenuStates: array[Boolean {MouseInControl}, Boolean {Selected}] of TThemedMenu =
((tmMenuBarItemNormal, tmMenuBarItemPushed), (tmMenuBarItemHot, tmMenuBarItemPushed));
var
BannerRect: TRect;
StartCol, EndCol: TColor;
begin
Canvas.Brush.Color := ActionBar.ColorMap.Color;
Canvas.Font := ActionBar.Font;
StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(MenuStates[MouseInControl, (State=bsDown)]), PaintRect);
end;

现在在你的TActionMainMenuBar.OnGetControlClass中添加这个简单的代码,并设置为有缺陷的actionclients tag=-100


procedure TfrmActions.ActionMainMenuBar1GetControlClass(Sender: TCustomActionBar; AnItem: TActionClient; var ControlClass: TCustomActionControlClass);
begin
if ControlClass.InheritsFrom(TCustomMenuButton) and then
begin
if (AnItem.Tag =-100) and (ControlClass = TThemedMenuButton) then
ControlClass := TFastThemedButton;
end;
end;

好了,现在所有带有 -100 标签的根项目都可以按照我们的意愿工作

关于delphi - 解决 TActionMainMenuBar 绘画错误,其中项目未取消选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14912858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com