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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
   |  
var ColonneEncours:integer;
...
// voir FAQ : Comment accéder aux variable privées d'une classe ?
type THookGrid = class(TCustomControl)
public
    FAnchor: TGridCoord;
    FBorderStyle: TBorderStyle;
    FCanEditModify: Boolean;
    FColCount: Longint;
    FColWidths: Pointer;
    FTabStops: Pointer;
    FCurrent: TGridCoord;
    FDefaultColWidth: Integer;
    FDefaultRowHeight: Integer;
    FFixedCols: Integer;
    FFixedRows: Integer;
    FFixedColor: TColor;
    FGridLineWidth: Integer;
    FOptions: TGridOptions;
    FRowCount: Longint;
    FRowHeights: Pointer;
    FScrollBars: TScrollStyle;
    FTopLeft: TGridCoord;
    FSizingIndex: Longint;
    FSizingPos, FSizingOfs: Integer;
    FMoveIndex, FMovePos: Longint;
    FHitTest: TPoint;
    FInplaceEdit: TInplaceEdit;
    FInplaceCol, FInplaceRow: Longint;
    FColOffset: Integer;
    FDefaultDrawing: Boolean;
    FEditorMode: Boolean;
end;
 
procedure TForm1.DrawGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var IndexColonne,Pos,ofs:integer;
    Largeur:Integer;
    ARect:TRect;
begin
  //FSizingIndex donne le numéro de colonne en cours de redimensionnement
  //Mais que si FSizingIndex<>-1 et que si bouton gauche de la souris enfoncé
  IndexColonne:=THookGrid(DrawGrid1).FSizingIndex;
 
  //FSizingPos Donne la position du trait vertical dessiné
  //pendant le redimensionnement
  Pos:=THookGrid(DrawGrid1).FSizingPos; 
 
   //FSizingPos Donne la position du trait vertical par rapport au bord 
  //de la cellule, enfin je crois... :( 
  ofs:=THookGrid(DrawGrid1).FSizingOfs;
 
  //On récupère les dimensions de la cellule du haut
  if IndexColonne>=0 then
  ARect:=DrawGrid1.CellRect(IndexColonne,0);
 
  Largeur:=Pos+ofs-ARect.Left; //(NouvelleLargeur:=NewRight-Left)
  if (ssLeft in Shift) then //L'info dans indexColonne 
                                 //n'est fiable que si le bouton gauche de la souris 
                                //est enfoncé
  if (IndexColonne<>-1)
  then begin
           //OnColSising :)
         Label1.Caption:=Format('colonne : %d Largeur :%d',[IndexColonne,Largeur]);
         ColonneEncours:=IndexColonne;
       end
  else begin
         Label1.Caption:='Pas de redimensionnement';
         ColonneEncours:=-1; //Comme ça, le mouseup n'affichera rien
       end;
end;
 
procedure TForm1.DrawGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  //OnColSisingFinished :)
  if ColonneEncours<>-1 then
  Label1.Caption:=Format('colonne : %d Largeur :%d',[ColonneEncours,DrawGrid1.ColWidths[ColonneEncours]]);
end; | 
Partager