1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
pt: TPoint;
GridCoord: TGridCoord;
CellRect: TRect;
IconSpacing, IconWidth, IconLeft, IconTop: Integer;
IconRect: TRect;
begin
if Column.Title.Caption <> 'Actions' then
Exit;
// Récupérer la position de la souris dans les coordonnées client du DBGrid
pt := DBGrid1.ScreenToClient(Mouse.CursorPos);
GridCoord := DBGrid1.MouseCoord(pt.X, pt.Y);
// Obtenir le rectangle de la cellule en cours
CellRect := TDBGridLandGreen(DBGrid1).CellRect(GridCoord.X, GridCoord.Y);
// Calcul des coordonnées de l'icône :
IconSpacing := 4;
IconWidth := ImageList1.Width;
IconTop := CellRect.Top + (CellRect.Bottom - CellRect.Top - ImageList1.Height) div 2;
IconLeft := CellRect.Left + IconSpacing;
// Première icône (par exemple, décrémentation)
IconRect := Rect(IconLeft, IconTop, IconLeft + IconWidth, IconTop + ImageList1.Height);
if PtInRect(IconRect, pt) then
begin
ShowMessage('Icône décrémentation cliquée');
Exit;
end;
// Deuxième icône (par exemple, incrémentation)
IconLeft := IconLeft + IconWidth + IconSpacing;
IconRect := Rect(IconLeft, IconTop, IconLeft + IconWidth, IconTop + ImageList1.Height);
if PtInRect(IconRect, pt) then
begin
ShowMessage('Icône incrémentation cliquée');
Exit;
end;
// Etc................................
end; |
Partager