Force display of a ToolButton's PopupMenu when the button is clicked #197

Delphi's TToolBar control manages tool buttons, TToolButton controls. Typically, the tool buttons correspond to items in an application's menu and give the user more direct access to the application's commands.

Depending on the Style property of the button placed on a tool bar, a button, a drop down button, a text button or a divider will be displayed to the user. Tool buttons can act like regular push buttons; toggle on and off when clicked and can act like a set of radio buttons.

When tool button's Style is set to tbsDropDown, the button displays a down-pointing arrow (suitable for accessing a drop-down menu). When its DropDownMenu property points to an instance of a TPopupMenu, the button when clicked will display the associated popup menu. The actual popup menu will get displayed ONLY when you click the down-pointing arrow.

If a user clicks on the button itself and not on the down-pointing arrow the popup menu will NOT get displayed.

To make sure that the drop down menu gets displayed when you click on the button, as opposed to clicking on the down-pointing arrow, you need to handle button's OnClick event and force the display of the associated popup menu. Fortunately, there's a CheckMenuDropdown method of the tool button that you can call to manually display a button’s pop-up menu. It returns true and displays the menu if the tool button has an associated menu. It returns false if there is no menu to display.

//ensure DropDownMenu Popup to pop up when button is clicked.
procedure TForm.dropDownMenuButtonClick(Sender: TObject) ;
  //dropDownMenuButton is the name of the tool button
  //with Style set to tbsDropDown and assigned DropDownMenu
Author: Unknown
Contributor: topellina
Added: 2012/09/17
Last updated: 2012/09/17