Firemonkey MouseToCell等效项 [英] Firemonkey MouseToCell equivalent
问题描述
在Delphi VCL中,如果我想查看鼠标悬停在TStringGrid的哪个单元格(列和行)上,可以使用MouseToCell.对于FireMonkey应用程序,Delphi(XE2)中不再使用此方法.有谁知道我如何确定鼠标悬停的单元格? OnMouseMove具有X&是Y值,但它们是屏幕坐标,而不是单元格坐标.
In Delphi VCL if I wanted to see which cell (column and row) of a TStringGrid my mouse was hovering over I'd use MouseToCell. This method is no longer in Delphi (XE2) for FireMonkey apps. Does anyone know how I can determine the cell my mouse is over? OnMouseMove has X & Y values but these are screen coordinates and not cell coordinates.
非常感谢.
推荐答案
在TCustomGrid
中实际上有一个MouseToCell
方法,StringGrid继承该方法,但它是私有的.从其来源看,它使用了ColumnByPoint
和RowByPoint
方法,所幸的是它们是公共的.
There's actually a MouseToCell
method in TCustomGrid
, which the StringGrid descends, but it's private. Looking at its source, it makes use of ColumnByPoint
and RowByPoint
methods, which are fortunately public.
'column'返回一个TColumn
,如果没有列,则返回nil. 行"返回一个正整数,如果没有行,则返回-1.此外,第一行并不关心行数,它仅考虑行高,即使没有行也将基于此返回行号.另外,我应该注意,网格标题上的行为是错误的.无论如何,示例示例可能像:
The 'column' one returns a TColumn
, or nil if there's no column. The 'row' one returns a positive integer, or -1 when there's no row. Furthermore, the row one does not care the row count, it just accounts for row height and returns a row number based on this, even if there are no rows. Also, I should note that, behavior on grid header is buggy. Anyway, sample example could be like:
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;
这篇关于Firemonkey MouseToCell等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!