Skip to main content

How to Add Custom Items to a Toolbar's Popup Menu

  • 2 minutes to read

This example demonstrates how you can add your own items to the Toolbars Popup Menu.

Let’s add the Show Captions option to this popup menu. This option toggles the captions of all TdxBarLargeButtons within toolbars.

The following code snippet adds a new button within a bar manager’s OnShowToolbarsPopup event handler.

// ...
uses
  ..., dxBarExtItems;
// ...
btnShowCaptions: TdxBarButton;
// ...
// The OnClick event handler of the ShowCaptions button
procedure TMainForm.btnShowCaptionsClick(Sender: TObject);
var
  I: Integer;
begin
  dxBarManager.BeginUpdate;
    try
      for I := 0 to dxBarManager.ItemCount - 1 do
        if dxBarManager.Items[I] is TdxBarLargeButton then
          TdxBarLargeButton(dxBarManager.Items[I]).ShowCaption := btnShowCaptions.Down;
    finally
      dxBarManager.EndUpdate;
    end;
end;
// The OnShowToolbarsPopup event handler
procedure TMainForm.dxBarManagerShowToolbarsPopup(Sender: TdxBarManager; PopupItemLinks: TdxBarItemLinks);
var
  ABarItemLink: TdxBarItemLink;
begin
  if btnShowCaptions = nil then
    begin
      btnShowCaptions := Sender.AddButton;
      btnShowCaptions.ButtonStyle := bsChecked;
      btnShowCaptions.Caption := 'Show Captions';
      btnShowCaptions.Down := True;
      btnShowCaptions := btnShowCaptionsClick;
    end;
  end;
  ABarItemLink := PopupItemLinks.Add;
  ABarItemLink.BeginGroup := True;
  ABarItemLink.Item := btnShowCaptions;
end;