Delphi Custom popup/dropdown, how?

天大地大妈咪最大 提交于 2019-12-04 17:44:29
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);
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;

alt text http://img718.imageshack.us/img718/8171/formlookslikepopup.png

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.

willw

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!