0

I would like to know how I can add a scroll bar to a popup menu in delphi that contains many elements.

 if Copy(trama, 1, 3) = 'ICO' then
    begin
      Inc(histo_hq);
      j := 1;
      for k := 1 to Length(trama) do
      begin
        if (Copy(trama, k, 1) = '|') then
        begin
          deli[j] := k;
          Inc(j);
        end;
      end;

      try

        menuItem_auxstate := TMenuItem.Create(PM_new_status);

        menuItem_auxstate.OnClick := PopupItemClick;
        menuItem_auxstate.ImageIndex := -1;
        menuItem_auxstate.Caption := trim(Copy(trama, deli[2] + 1, deli[3] - deli[2] - 1));
        menuItem_auxstate.Tag := strtoint(trim(Copy(trama, deli[3] + 1, deli[4] - deli[3] - 1)));
        PM_new_status.Items.Add(menuItem_auxstate);

        new_agent_status[histo_hq, 1] := trim(Copy(trama, deli[1] + 1, deli[2] - deli[1] - 1));
        new_agent_status[histo_hq, 2] := trim(Copy(trama, deli[2] + 1, deli[3] - deli[2] - 1));
        new_agent_status[histo_hq, 3] := trim(Copy(trama, deli[3] + 1, deli[4] - deli[3] - 1));
      except

      end;

      Panel_top.Enabled := True;
    end;

the reason is that my menu overflows, and some options cannot be seen on screens.

problem - menu overflow

thank you.

jdoc
  • 1
  • You do know, don't you, that you can have main items and also subitems in popup menus. – Tom Brunberg Sep 07 '22 at 16:26
  • You can also break the submenu into columns. – Andreas Rejbrand Sep 07 '22 at 16:27
  • I understand what they say but they don't give me a solution. In this case no submenus apply. And adding Break I don't know how to do it correctly, since the elements are automatically generated so the bar ends up going from vertical to horizontal... menuItem_auxstate.Break := mbBarBreak; – jdoc Sep 07 '22 at 16:40
  • Look at [this q/a](https://stackoverflow.com/questions/10947836/how-to-make-a-popup-menu-with-scrollbar) and [this one](https://stackoverflow.com/questions/41618290/how-to-create-popup-menu-with-scroll-bar-that-also-supports-sub-menus) – Tom Brunberg Sep 07 '22 at 16:52
  • @jdoc: If you always generate the menu from scratch, it is easy to make every Nth item have `Break := mbBarBreak`. Maybe N = 16 is a good choice for you? (Declare `var LCount := 0;` before your loop, do `Inc(LCount)` in each iteration, and set the `Break` if `LCount mod N = 0`.) – Andreas Rejbrand Sep 07 '22 at 17:18
  • I appreciate the possibilities they offer, but if the menu is split in half and shown in another column, it is not something that looks good, that is why I am looking for a way to add a scroll. – jdoc Sep 07 '22 at 19:13
  • @jdoc A popup menu with scrollbar also doesn't look good. Additionally it has bad usability. – Uli Gerhardt Sep 07 '22 at 20:44
  • @uli garhardt no one takes away your reason but it's what they ask me to do :( – jdoc Sep 07 '22 at 20:49

0 Answers0