本文介绍了带有Delphi VCL样式的扁平工具栏按钮-是否通过下拉菜单固定工具栏项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is a follow-up to this question about making toolbar buttons flat when VCL styles are enabled. Using the solution in that question, now most of my TActionToolbar buttons are flat. However, there's one toolbar button with a drop-down menu with additional actions:

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

And it's still drawing button edges around it. How can I remove the button borders for toolbar buttons with drop-downs so they match the other plain buttons, and look more like when VCL styles were disabled?

推荐答案

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

This kind of button is draw by the TThemedDropDownButton class, So you must override this class and the TThemedDropDownButton.DrawBackground method.

使用与上一个答案相同的单元添加一个名为TThemedDropDownButtonEx

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

然后像这样实现DrawBackground方法

Then implement the DrawBackground method like so

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 方法

and Finally modify the TPlatformVclStylesStyle.GetControlClass method on this way

更改此代码

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

这篇关于带有Delphi VCL样式的扁平工具栏按钮-是否通过下拉菜单固定工具栏项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:08