您可以使用TGridPanel.CellRect
获得的边框为每个细胞。以下是如何使用CellRect
的示例:
// GP: TGridPanel
// This is the "OnDragDrop" handler.
procedure TForm13.GPDragDrop(Sender, Source: TObject; X, Y: Integer);
var DropPoint: TPoint;
CellRect: TRect;
i_col, i_row: Integer;
begin
if Source = Panel1 then // Simple test, is this a drop I want to handle?
begin
DropPoint := Point(X, Y); // Where did the suer drop? We need this so we can easily call PtInRect
for i_col := 0 to GP.ColumnCollection.Count-1 do
for i_row := 0 to GP.RowCollection.Count-1 do
begin
CellRect := GP.CellRect[i_col, i_row]; // Get the bounding rect for Col[i_col, i_row]
if PtInRect(CellRect, DropPoint) then
begin
// Panel1 was dropped over Cell[i_col, i_row]
end;
end;
end;
end;