function IsCellSelected(StringGrid : TStringGrid; X, Y : LONGINT): BOOLEAN;
begin
Result := false;
try
if (X >= StringGrid.Selection.Left) and (X <= StringGrid.Selection.Right) and (Y >= StringGrid.Selection.Top) and (Y <= StringGrid.Selection.Bottom)
then
Result := true;
except
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsCellSelected(Stringgrid1,2,2) then
begin
ShowMessage('Cell 2,2 is selected');
end;
end;
检测表格单元格选择状态
本文介绍了一个简单的Delphi函数IsCellSelected,用于检测指定位置的单元格是否处于选中状态。通过比较单元格坐标与表格选区边界,该函数能够准确判断单元格是否被选中,并提供了一个示例展示如何在按钮点击事件中调用此函数。
1575

被折叠的 条评论
为什么被折叠?



