2

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?

Roy M Klever
  • 353
  • 5
  • 15

3 Answers3

4

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.

Robert Love
  • 12,447
  • 2
  • 48
  • 80
  • Hi Robert, Thank you for that link but I do not think I can put a scrollbar on a tpopupmenu but it is a nice article. I am trying to mimic the dropdown of the breadcrumb bar in Vista so I must be able to add a scrollbar or listview onto the dropdown panel. – Roy M Klever Jun 07 '10 at 22:54
  • Then the TPopupMenu can not be used. The closest thing I have seen that might do that is a commercial product from TMS Software called Advanced Poly Lists. Although I have a license to it I have not had a chance to use it yet as it was just released. http://www.tmssoftware.com/site/advpolylist.asp?s= – Robert Love Jun 07 '10 at 23:01
  • Thank you Robert, I guess it is a rather difficult task but I have had some success in trying to get a panel acting like a popup/dropdown with a dropshadow. It is good to see I have some option if this do not work out like I want it too. – Roy M Klever Jun 09 '10 at 20:59
  • @JerryDodge I removed the link from the answer. – Robert Love Sep 13 '17 at 13:40
4

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);
begin
  if Button=mbRight then
        FDown := true
  else
        FDown := false;
end;

procedure TForm3.JvPanel1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  pt:TPoint;
begin
  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;
        Form4.Show;
  end;

end;

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);
begin
 Hide;
end;
Zen Of Kursat
  • 2,672
  • 1
  • 31
  • 47
Warren P
  • 65,725
  • 40
  • 181
  • 316
  • Thanks,yes that could be a solution but not exactly what I need, as I want it to resemble a popupmenu with a shadow. I do have a solution now that will show a panel with dropshadow and behaves more or less as a popupmenu. I dont know if I can post the full solution here but I will post it on my blog sooner or later. Any limits on code size you can post here? – Roy M Klever Jun 12 '10 at 16:31
  • The shadow to me could just be another window you show with alpha blending at 50%. – Warren P Apr 07 '14 at 17:09
  • Sadly I used imageshack, not imgur, and that image is gone. – Warren P Sep 29 '17 at 17:54
-1

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

Community
  • 1
  • 1
willw
  • 1,308
  • 13
  • 28
  • No it hasn't been "tacked and solved" quite yet, the solution in that question doesn't work for everyone. That's actually what brought me here :-) – Jerry Dodge Dec 20 '14 at 20:01