我想知道何时在TDBGrid中双击记录,但是无论在网格中的哪个位置单击,都会触发OnDblClick事件。
在Delphi中,是否有一种很好的、干净的方法来确定标题上是否有TDBGrid双击?
发布于 2013-11-29 01:41:07
我就是这样做的,它只是计算这个位置是否与标题相符:
function GridClickIsOnTitle(Grid: TDbGrid): Boolean;
var
Pt: TPoint;
begin
Pt := Grid.ScreenToClient(SmallPointToPoint(types.SmallPoint(GetMessagePos)));
Result := (Grid.MouseCoord(Pt.X, Pt.Y).Y = 0) and (dgTitles in Grid.Options);
end;我从OnDblClick处理程序调用它。
发布于 2016-06-09 09:55:17
// in the class declaration
type
THackDBGrid=Class(TDBGrid);
// function to check if click is on the title
function isClickOnTitle(const dbGrid: TDbGrid; const rowTitleHeight : integer): Boolean;
var
mousePoint : TPoint;
mouseInGrid : TPoint;
begin
mousePoint := Mouse.CursorPos;
mouseInGrid := dbGrid.ScreenToClient(mousePoint);
result := mouseInGrid.Y <= rowTitleHeight;
end;
// grid double click event
procedure TForm.dbGridDblClick(Sender: TObject);
var
rowTitleHeight : integer;
begin
inherited;
// trick to get the title row height
rowTitleHeight := THackDBGrid(gdTestGrid).RowHeights[0];
if not isClickOnTitle(gdTestGrid, rowTitleHeight) then begin
bbOk.click;
end;
end;https://stackoverflow.com/questions/20277041
复制相似问题