Flat toolbar buttons with Delphi VCL Styles--fixing toolbar items with dropdowns?

旧街凉风 提交于 2019-12-10 20:56:47

问题


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:

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?


回答1:


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

Using the same unit of the previous answer add a new class called TThemedDropDownButtonEx

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

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;

and Finally modify the TPlatformVclStylesStyle.GetControlClass method on this way

Change this code

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

by this

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



来源:https://stackoverflow.com/questions/16842046/flat-toolbar-buttons-with-delphi-vcl-styles-fixing-toolbar-items-with-dropdowns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!