How does the TrackButton property work on the TPopupMenu component?

95 Views Asked by At

I don't understand how the TrackButton property works.

Specifies which mouse button activates the popup menu when it is associated with a toolbar button. Use TrackButton to specify which mouse button activates the popup menu when it is associated with a toolbar button.

So firstly. It only works on a TToolButton and nothing else?

I have a TToolButton with my popup assigned to it via the PopUpMenu property on the TToolButton, but it doesn't seem to work. I set the TrackButton to tbLeftButton, but it still opens with right click?

Or what am I not understanding? Can someone explain how it works please?

1

There are 1 best solutions below

2
On

This has nothing to do with TToolBar and also not with any potential button on it.

As of Delphi 5 TPopupMenu.TrackButton is only used in TPopupMenu.Popup(), where its value (of either tbRightButton or tbLeftButton) is mapped to WinAPI's TPM_RIGHTBUTTON and TPM_LEFTBUTTON to be used (among others) as flags in the call to TrackPopupMenu(). There those constants have the following meaning:

constant value description
TPM_LEFTBUTTON 0 The user can select menu items with only the left mouse button.
TPM_RIGHTBUTTON 2 The user can select menu items with both the left and right mouse buttons.

Which means:

  • .TrackButton applies to any popup menu anywhere, and
  • it enables/disables to click on menu items also with the right mouse button (while the left mouse button is always available).