如何通过下拉菜单在Delphi VCL工具栏中修复并优化工具栏按钮项目?

2026-04-10 20:382阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计374个文字,预计阅读时间需要2分钟。

如何通过下拉菜单在Delphi VCL工具栏中修复并优化工具栏按钮项目?

关于在启用VCL样式时工具栏按钮变平的后续行动。使用该问题的解决方案,现在我的多数TActionToolbar按钮都是扁平的。但是,有一个工具栏按钮,其下拉菜单包含其他操作。

这是关于在启用VCL样式时使工具栏按钮变平的 this question的后续行动.使用该问题的解决方案,现在我的大多数TActionToolbar按钮都是扁平的.但是,有一个工具栏按钮,其下拉菜单包含其他操作:

它仍然在它周围绘制按钮边缘.如何删除带有下拉菜单的工具栏按钮的按钮边框,以便它们与其他普通按钮匹配,看起来更像是在禁用VCL样式时?

这种按钮是由TThemedDropDownButton类绘制的,因此必须覆盖此类和TThemedDropDownButton.DrawBackground方法.

使用same unit of the previous answer添加一个名为TThemedDropDownButtonEx的新类

如何通过下拉菜单在Delphi VCL工具栏中修复并优化工具栏按钮项目?

TThemedDropDownButtonEx= class(TThemedDropDownButton) protected procedure DrawBackground(var PaintRect: TRect); override; end;

然后像这样实现DrawBackground方法

procedure TThemedDropDownButtonEx.DrawBackground(var PaintRect: TRect); const CheckedState: array[Boolean] of TThemedToolBar = (ttbButtonHot, ttbButtonCheckedHot); var LIndex : Integer; begin LIndex := SaveDC(Canvas.Handle); try if Enabled and not (ActionBar.DesignMode) then begin if (MouseInControl or IsChecked or DroppedDown) and (Assigned(ActionClient) and not ActionClient.Separator) then begin StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(CheckedState[IsChecked or (FState = bsDown)]), PaintRect); if IsChecked and not MouseInControl then StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(ttbButtonPressed), PaintRect); end else ; end else ; finally RestoreDC(Canvas.Handle, LIndex); end; end;

最后以这种方式修改TPlatformVclStylesStyle.GetControlClass方法

更改此代码

if AnItem.HasItems then case GetActionControlStyle of csStandard: Result := TStandardDropDownButton; csXPStyle: Result := TXPStyleDropDownBtn; else Result := TThemedDropDownButton; end else

这样

if AnItem.HasItems then case GetActionControlStyle of csStandard: Result := TStandardDropDownButton; csXPStyle: Result := TXPStyleDropDownBtn; else Result := TThemedDropDownButtonEx; end else

本文共计374个文字,预计阅读时间需要2分钟。

如何通过下拉菜单在Delphi VCL工具栏中修复并优化工具栏按钮项目?

关于在启用VCL样式时工具栏按钮变平的后续行动。使用该问题的解决方案,现在我的多数TActionToolbar按钮都是扁平的。但是,有一个工具栏按钮,其下拉菜单包含其他操作。

这是关于在启用VCL样式时使工具栏按钮变平的 this question的后续行动.使用该问题的解决方案,现在我的大多数TActionToolbar按钮都是扁平的.但是,有一个工具栏按钮,其下拉菜单包含其他操作:

它仍然在它周围绘制按钮边缘.如何删除带有下拉菜单的工具栏按钮的按钮边框,以便它们与其他普通按钮匹配,看起来更像是在禁用VCL样式时?

这种按钮是由TThemedDropDownButton类绘制的,因此必须覆盖此类和TThemedDropDownButton.DrawBackground方法.

使用same unit of the previous answer添加一个名为TThemedDropDownButtonEx的新类

如何通过下拉菜单在Delphi VCL工具栏中修复并优化工具栏按钮项目?

TThemedDropDownButtonEx= class(TThemedDropDownButton) protected procedure DrawBackground(var PaintRect: TRect); override; end;

然后像这样实现DrawBackground方法

procedure TThemedDropDownButtonEx.DrawBackground(var PaintRect: TRect); const CheckedState: array[Boolean] of TThemedToolBar = (ttbButtonHot, ttbButtonCheckedHot); var LIndex : Integer; begin LIndex := SaveDC(Canvas.Handle); try if Enabled and not (ActionBar.DesignMode) then begin if (MouseInControl or IsChecked or DroppedDown) and (Assigned(ActionClient) and not ActionClient.Separator) then begin StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(CheckedState[IsChecked or (FState = bsDown)]), PaintRect); if IsChecked and not MouseInControl then StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(ttbButtonPressed), PaintRect); end else ; end else ; finally RestoreDC(Canvas.Handle, LIndex); end; end;

最后以这种方式修改TPlatformVclStylesStyle.GetControlClass方法

更改此代码

if AnItem.HasItems then case GetActionControlStyle of csStandard: Result := TStandardDropDownButton; csXPStyle: Result := TXPStyleDropDownBtn; else Result := TThemedDropDownButton; end else

这样

if AnItem.HasItems then case GetActionControlStyle of csStandard: Result := TStandardDropDownButton; csXPStyle: Result := TXPStyleDropDownBtn; else Result := TThemedDropDownButtonEx; end else