Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: MainMenu ownerdrawn vs. Styles

  Alt 21. Sep 2020, 10:47
Ich kann nicht für Deine Delphi Version sprechen. Bei 10.3 bin ich so an styled menus gekommen.
Es ist aufwändiger aber man mag was hinten raus kommt, sprich: es lohnt sich!

how-to-add-submenus-to-tactionmainmenubar-programatically auf stackoverflow zeigt einem wie man dynamisch vorgehen könnte.

Delphi-Quellcode:
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  iActionClientItem : TActionClientItem;
  iSubMenuItem : TActionClientItem;
  iFileAction : TCustomAction;
  iChildMenu : TActionBarItem;
begin
  ActionManager1.AddSeparator( ActionManager1.FindItemByAction(FileExit1), FALSE );
  iActionClientItem := ActionManager1.AddSeparator( ActionManager1.FindItemByAction(FileExit1) );
  iFileAction := TCustomAction.Create( self ); // we want to put in same collection
  iFileAction.Caption := 'Fred';
  // etc.. to build what is wanted
  iActionClientItem := ActionManager1.AddAction( iFileAction, iActionClientItem ) ;

  //*********************************
  // Build sub menu (from Fred) - stage 1 add the visual element - a new action bar
  iChildMenu := ActionManager1.ActionBars.Add;
  iActionClientItem.ChildActionBar := iChildMenu.ActionBar;

  // we add a dummy entry that we can build from.
  // We could set the properties manually, but when we use the action manager
  // it does that automatically, so it is easier just to set this item to not visible
  // then use action manager to do the rest.
  iSubMenuItem := iActionClientItem.Items.Add;
  iSubMenuItem.Visible := FALSE;

  // Now the real build...

  iFileAction := TCustomAction.Create( self ); // we want to put in same collection
  iSubmenuItem := ActionManager1.AddAction( iFileAction, iSubMenuItem );
  iSubmenuItem.Caption := 'Fred 1';
  // etc

  iFileAction := TCustomAction.Create( self ); // we want to put in same collection
  iSubmenuItem := ActionManager1.AddAction( iFileAction, iSubMenuItem );
  iSubmenuItem.Caption := 'Fred 2';
  // etc
end;
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat