Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi Firemonkey鼠细胞等效物_Delphi_Mouse_Coordinates_Firemonkey_Tstringgrid - Fatal编程技术网

Delphi Firemonkey鼠细胞等效物

Delphi Firemonkey鼠细胞等效物,delphi,mouse,coordinates,firemonkey,tstringgrid,Delphi,Mouse,Coordinates,Firemonkey,Tstringgrid,在Delphi VCL中,如果我想查看TStringGrid的哪个单元格(列和行),我会使用MouseToCell。FireMonkey应用程序的Delphi(XE2)中不再使用此方法。有人知道我如何确定鼠标所在的细胞吗?OnMouseMove有X&Y值,但这些是屏幕坐标,而不是单元格坐标 非常感谢。在TCustomGrid中实际上有一个MouseToCell方法,StringGrid会将其下降,但它是私有的。从源代码看,它使用了ColumnByPoint和RowByPoint方法,幸运的是这些

在Delphi VCL中,如果我想查看TStringGrid的哪个单元格(列和行),我会使用MouseToCell。FireMonkey应用程序的Delphi(XE2)中不再使用此方法。有人知道我如何确定鼠标所在的细胞吗?OnMouseMove有X&Y值,但这些是屏幕坐标,而不是单元格坐标


非常感谢。

TCustomGrid
中实际上有一个
MouseToCell
方法,StringGrid会将其下降,但它是私有的。从源代码看,它使用了
ColumnByPoint
RowByPoint
方法,幸运的是这些方法是公开的

“column”one返回一个
t列,如果没有列,则返回nil。“row”1返回一个正整数,如果没有行,则返回-1。此外,行1不关心行数,它只考虑行高并基于此返回行号,即使没有行。另外,我应该注意到,网格头上的行为是有缺陷的。无论如何,示例可能如下所示:

procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
var
  Col: TColumn;
  C, R: Integer;
begin
  Col := StringGrid1.ColumnByPoint(X, Y);
  if Assigned(Col) then
    C := Col.Index
  else
    C := -1;
  R := StringGrid1.RowByPoint(X, Y);

  Caption := Format('Col:%d Row:%d', [C, R]);
end;

TStringGrid
具有
ColumnByPoint
RowByPoint
方法

ColumnByPoint
RowByPoint
按字符串网格的坐标进行。因此,如果使用字符串网格的
OnMouseOver
,X和Y参数将已经在字符串网格的坐标中

以下是如何在字符串网格的OnMouseOver中显示行和列(基于0):

var
  row: Integer;
  col: TColumn;
  colnum: Integer;
begin
  row := StringGrid1.RowByPoint(X, Y);
  col := StringGrid1.ColumnByPoint(X, Y);
  if Assigned(col) then
  begin
    colnum := col.Index;
  end
  else
  begin
    colnum := -1;
  end;
  Label1.Text := IntToStr(row) + ':' + IntToStr(colnum);
end;

请注意,
-1
将在超出行和列的边界时显示。

非常感谢各位:)@SertacAkyuz,当我在写我的答案时,通常会在有其他答案时显示。这次没有。我想既然我花了这么多时间在它上面,而且它还有一些额外的信息,我就把它留下。@Marcus-好的。谢谢你告诉我。我有点好奇……)