delphi TPopupMenu.Popup

delphi TPopupMenu.Popup
 
procedure TPopupMenu.Popup(X, Y: Integer);
 
 
这个点是相对桌面的而不是窗体的
 
GetCursorPos是鼠标的位置 鼠标动这个点就不一样
 
var
  p:TPoint;
begin
   GetCursorPos(p);
   PopupMenu1.Popup(p.x,p.Y);
end;
 
 
现在要取得 Button1的Left 和Bottom的值 菜单就在这个位置出现
 
procedure TForm1.Button1Click(Sender: TObject);
var
    p:TPoint;
begin
     p.X:=Button1.Left;
     p.y:=Button1.Top +Button1.Height;
     p:=Self.ClientToScreen(p);
     PopupMenu1.Popup(p.x,p.y);
end;
 
 
 
同样适用窗体的Show
 
 
function GetControlPos(frm:TForm;ctrl:TControl):TPoint;
var
    p:TPoint;
begin
     p.X:=ctrl.Left;
     p.y:=ctrl.Top +ctrl.Height;
     p:=frm.ClientToScreen(p);
     Result:=p;
end;
 
 
 
 
procedure TForm1.Button2Click(Sender: TObject);
var
    p:TPoint;
begin
    p:=GetDeskPos(Self,Button2);
    PopupMenu1.Popup(p.X,p.Y);
end;
 
 
 




你可能感兴趣的:(Delphi)