首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >确定TDBGrid的标题中是否有双击

确定TDBGrid的标题中是否有双击
EN

Stack Overflow用户
提问于 2013-11-29 01:25:01
回答 2查看 2K关注 0票数 1

我想知道何时在TDBGrid中双击记录,但是无论在网格中的哪个位置单击,都会触发OnDblClick事件。

在Delphi中,是否有一种很好的、干净的方法来确定标题上是否有TDBGrid双击?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-29 01:41:07

我就是这样做的,它只是计算这个位置是否与标题相符:

代码语言:javascript
复制
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处理程序调用它。

票数 5
EN

Stack Overflow用户

发布于 2016-06-09 09:55:17

代码语言:javascript
复制
// 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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20277041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档