Board index » cppbuilder » Poping up a menu over a button

Poping up a menu over a button

I need to know how to drop down a menu when a user clicks on a specific
button or panel.

Thanks,
Beebs

 

Re:Poping up a menu over a button


Hi Beebs,

The easiest way is to add a TPopupMenu on your form, double clicked on
it to add some functions (menu items). Then, for TButton or TPanel,
via the object inspector, you will find a PopupMenu property. Click on
it and you will see the list of all TPopupMenu dropped on your form.
Select one and voil! Now, at runtime, when the right mouse button
will be clicked while over the TButton or TPanel, the popup menu will
"popup".

I hope that this will help.

Stphane

Re:Poping up a menu over a button


I use this method to pop up a menu that is aligned exactly under a
button. The form contains a button (LegendBtn) and a popup menu
(LegendMenu).

void __fastcall TEqImportMapFrame::LegendBtnClick(TObject *Sender)
{
  LegendMenu->Popup(LegendBtn->ClientOrigin.x,
      Top + LegendBtn->ClientOrigin.y + LegendBtn->Height);

Quote
}

Jim
Quote
Beebs wrote:

> I need to know how to drop down a menu when a user clicks on a specific
> button or panel.

> Thanks,
> Beebs

Re:Poping up a menu over a button


BTW, I used 'Top' when calculating the y-coord because the button is on
a frame that is maximized to the form's client area. If the button was
placed directly on a form I think you would leave 'Top' out.

Jim

Quote
Jim Melsom wrote:

> I use this method to pop up a menu that is aligned exactly under a
> button. The form contains a button (LegendBtn) and a popup menu
> (LegendMenu).

> void __fastcall TEqImportMapFrame::LegendBtnClick(TObject *Sender)
> {
>   LegendMenu->Popup(LegendBtn->ClientOrigin.x,
>       Top + LegendBtn->ClientOrigin.y + LegendBtn->Height);
> }

Other Threads