Author: Tomas Rutkauskas
I have a PopupMenu, which contains a lot of menu items. Sometimes the user can't
see all menus on the screen. The same problem occurs with MainMenu. How I can split
PopupMenu at runtime that it will be all visible on the screen?
Answer:
TMenuItem has a Break property which you can use to split a menu up into columns.
The following procedure lets you specify the number of items you want in each
column:
1 procedure FormatMenu(item: TMenuItem; maxrows: integer);
2 var3 ix: integer;
4 item2: TMenuItem;
5 begin6 for ix := 1 to item.Count - 1 do{ignore first}7 begin8 item2 := item.Items[ix];
9 if ix mod maxrows = 0 then10 item2.Break := mbBreak
11 else12 item2.Break := mbNone;
13 end;
14 end;
15 16 17 //You call it like:18 19 20 FormatMenu(PopupMenu.Items, 4);
If instead of an absolute number, you want a specific number of columns, say three:
21 count := PopupMenu.Items.Count div 3;
22 if PopupMenu.Items.Count mod 3 > 0 then23 inc(count);
24 FormatMenu(PopupMenu.Items, count);