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;
 
delphi TPopupMenu.Popup
 
现在要取得 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;
 
 
 
上一篇:175. Combine Two Tables【LeetCode】-LEFT JON 和RIGHT JOIN,两张表关联查询-java -sql入门


下一篇:C#设计模式——抽象工厂模式(原文转自:http://blog.jobbole.com/78059/)