delphi7 怎么让button按钮跟着鼠标点击dbgrideh数据行移动

delphi7 怎么让button按钮跟着鼠标点击dbgrideh数据行移动

在 dbgrid的DBGridCellClick 事件中加上:

Delphi/Pascal code
 

1
2
3
4
5
6
7
8
9
10
11
var
  x, y : integer ;
  P: TPoint;
begin
  GetCursorPos(P);
  Edit1.Text := Format('X: %d, Y: %d',[P.X, P.Y]);
  x := frMainTest.Left ;
  y := frMainTest.Top ;
  Button.Top := P.Y - y - 45 ;
  Button.Left := P.X - x ;
  Button.BringToFront();



注: Button 的位置,需要根据你放置的容器不同而计算出相对位置。

GetCursorPos(P) 获取的是鼠标在屏幕的位置。

原文地址:https://www.cnblogs.com/lantianhf/p/7236444.html