Jessica Brown
Jessica Brown

Reputation: 8312

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

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:

enter image description here

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?

Upvotes: 3

Views: 1354

Answers (1)

RRUZ
RRUZ

Reputation: 136401

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

enter image description here

Upvotes: 7

Related Questions