Delphi Custom popup/dropdown, how?

0 votes
asked Jun 7, 2010 by roy-m-klever

I want to make a custom dropdow/popup menu with a shadow nicely beneath it. The problem is that it is not a standard menu and I need to put some components on the popup/dropdown. So basically I want a dropdown I can do whatever I want with, not being limited to simple menuitems. I want it to act like a normal popupmenu problem is where do I start. Any solutions? References?

3 Answers

0 votes
answered Jun 7, 2010 by robert-love

You can use TPopupMenu and provide custom drawing. This is done by setting

PopupMenu1.OwnerDraw := True;

Then code the OnMeasureItem() or OnAdvancedDrawItem() Event to determine the size you need for the custom painting. Then code the OnDrawItem() Event to paint the canvas as desired.

0 votes
answered Jun 10, 2010 by warren-p

It sounds like you want a form that looks like a popup menu, but contains components.

It is easier if you have a component that has an OnMouseDown event, like the TPanel shown in this sample, and you just pop up a second form which contains the controls you wanted to pop up:

procedure TForm3.JvPanel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  if Button=mbRight then
        FDown := true
        FDown := false;

procedure TForm3.JvPanel1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  if Button=mbRight then begin
        FDown := true;
        pt.X := jvPanel1.Left;
        pt.Y := jvPanel1.Top+jvPanel1.Height;

        pt := ClientToScreen(pt);
        Form4.Position := poDesigned;
        Form4.BorderStyle := bsNone;
        Form4.Left := pt.X;
        Form4.Top := pt.Y;


That handles the form showing itself, and positioning itself to look like a popup. the second form hiding itself, is easy too:

procedure TForm4.FormDeactivate(Sender: TObject);

alt text

0 votes
answered Jun 22, 2010 by willw

For what it is worth, the drop shadow aspect of the popup has now been tackled and solved in this question.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter