Drag N Drop Controls in GridPanel

I cheated by dragging the controls on the grid panel in delphi 2010. Move the panel / button / if the content is from one cell to another cell. Replacing existing or partitions. I did not understand how I know which cell was deleted because they work with column indices as well as row indices.

so if I have a grid that has 3 columns and 3 rows and I have a button in cell 1/1 ... and I drag this button from 1/1 to 3/3, how can I get this location cells from dragdrop event? I get the x, y coordinates on the drop, but how can I determine the cell from this?

0
source share
1 answer

You can use TGridPanel.CellRect to get a bounding box for each cell. Here is an example using 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; 
+3
source

Source: https://habr.com/ru/post/1344473/


All Articles