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

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

在 dbgrid的DBGridCellClick 事件中加上:
ide

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) 获取的是鼠标在屏幕的位置。
spa

相关文章
相关标签/搜索