更新时间:2022-12-11 17:42:54
听起来您想要一个看起来像弹出菜单但包含组件的表单.
It sounds like you want a form that looks like a popup menu, but contains components.
如果您有一个具有 OnMouseDown 事件的组件(如本示例中显示的 TPanel),并且您只需弹出包含您想要弹出的控件的第二个表单,那就更容易了:
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;