begin //创建MainMenu with BarManager.Bars.Add do begin Caption := 'Main Menu'; DockingStyle := dsTop; IsMainMenu := True; Visible := True;
end; //获取Mainmenubar.itemlins AItemLinks := BarManager.MainMenuBar.ItemLinks; ACategoryName := 'Menus'; BarManager.MainMenuBar.LockUpdate := True; //Get Category index with BarManager.Categories do begin if IndexOf(ACategoryName) < 0 then Add(ACategoryName); ACategory := IndexOf(ACategoryName); end;
for i:=1 to 4 do with SideBar do begin //创建组 g:=Groups.Add; with g do begin Index:=i-1; Caption:=Format('Group%d',[i]); IconType := dxsgSmallIcon; end; //创建主菜单单项目 AItem := TdxBarSubItem.Create(Form1); with AItem do begin Category := ACategory; Caption := g.Caption; end; //添加到主菜单 AItemLink:=AItemLinks.Add; AItemLink.Item:=AItem;
//创建组的子项目 for c:=1 to 5 do begin it:=g.Items.Add; with it do begin Index:=c-1; Caption:=Format('Group%d - Item %d',[i,c]); SmallImage:=0; //comm item click proc OnItemClick:=OnBarItemClick; //或使用action //Action:=act_XXX;
end; //创建子菜单 AChildItem:=TdxBarButton.Create(form1); with AChildItem do begin caption:=it.Caption; Visible:=ivAlways; OnClick:=OnMenuItemClick; ImageIndex:=0; //或使用action //Action:=act_XXX; end; //添加子菜单到主菜单 AItemLink := TdxBarSubItem(AItem).ItemLinks.Add; AItemLink.Item := AChildItem; end; end; with BarManager.Categories do Move(ACategory, Count - 1); BarManager.MainMenuBar.LockUpdate := False;
end;
procedure TForm1.FormDestroy(Sender: TObject); begin SideBar.Groups.Clear; BarManager.MainMenuBar.ItemLinks.Clear; end;
procedure TForm1.OnBarItemClick(Sender: TObject; Item: TdxSideBarItem); begin showmessage(item.Caption); end;
procedure TForm1.OnMenuItemClick(Sender: TObject); begin showmessage((sender as TdxBarButton).Caption); end;