A rather common question on StackOverflow, the Delphi newsgroups and elsewhere is how to display a drop down menu when the user presses a button.

A rather common question on StackOverflow, the Delphi newsgroups and elsewhere is how to display a drop down menu when the user presses a button.
There are many proposed solutions. Here is mine: ...
http://blog.dummzeuch.de/2014/08/31/showing-a-dropdown-menu-when-clicking-a-button/

Comments

  1. thanks for sharing, adding a quick screen shot of what the code produces is always great in my opinion as well

    ReplyDelete
  2. Brett Wilton difficult to do since pressing Alt (for Alt+Print) will close the dropdown menu...

    ReplyDelete
  3. lol.....hadnt thought of that....was thinking of my environment with VM's which would make it possible I'd expect

    ReplyDelete
  4. It would. All VMs that I know of allow screen shots from their menus that can be accessed without the programs running in them noticing.

    ReplyDelete
  5. Thomas Mueller It's not all that difficult if you just press PrtScr without Alt. It does mean you'll have to cut out the menu yourself, but there's many tools to do that.

    ReplyDelete
  6. Your component doesn't take into account that sometimes there is no space under the button (or on the right) to show the PM. Then the PM will be displayed over the button which is not very nice.
    You should calculate the PM size (that's possible) and then decide where to show the PM.

    ReplyDelete
  7. I was thinking whether I should cater for these issues but decided against it. So far I haven't encountered them and I didn't want to make the code more complex than necessary.

    ReplyDelete
  8. I wrote a custom popupmenu that calculates its size and positions itself properly in the screen already years ago. It's interesting that there are no tutorials or any ready-to-go components on the internet...
    Maybe I should sell it :)

    ReplyDelete
  9. You could write that tutorial.
    At work, we also have such a component, but that's proprietary code that I'm not at liberty to publish. Also, it's a component that is meant to be used in the form designer. I wanted a simple procedure that can be used to link any type of TCustomButton descendant to a pop-up menu.

    ReplyDelete

Post a Comment