Firemonkey MouseToCell相当于

Ian*_*cis 4 delphi mouse coordinates tstringgrid firemonkey

在Delphi VCL如果我想看到一个TStringGrid的哪个小区(列和行)我的鼠标盘旋在我会用MouseToCell.对于FireMonkey应用程序,此方法不再适用于Delphi(XE2).有谁知道我怎么能确定我的鼠标结束的细胞?OnMouseMove具有X和Y值,但这些是屏幕坐标而不是单元格坐标.

非常感谢.

Ser*_*yuz 7

实际上有一个MouseToCell方法TCustomGrid,StringGrid下降,但它是私有的.从它的来源来看,它使用ColumnByPointRowByPoint方法,幸运的是公开.

'column'返回a TColumn,如果没有列,则返回nil.'row'返回一个正整数,或者当没有行时返回-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;
Run Code Online (Sandbox Code Playgroud)