- Procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
- Rect: TRect; State: TGridDrawState);
- Var i,x,y:Integer;
- R:TRect;
- Begin
- With Sender As TStringGrid Do With Canvas Do
- Begin
- If gdFixed In State
- Then Begin
- // Les cellules fixes sont toujours dessinées en gris
- Brush.Color := clBtnFace;
- Brush.Style := bsSolid;
- FillRect(Rect);
- End
- Else If gdSelected In State
- Then Begin
- // Les cellules sélectionnées sont en bleue
- Brush.Color := clNavy;
- Brush.Style := bsSolid;
- FillRect(Rect);
- End
- Else Begin
- // Recherche de la zone image à copier pour tenir compte des décalages
- // de la grille en fonction des barres de défilement.
- X:=0; For i:=FixedCols+1 To ACol Do Inc(x,ColWidths [i]);
- Y:=0; For i:=FixedRows+1 To ARow Do Inc(Y,RowHeights[i]);
- R.Left :=X;
- R.Right :=X+Rect.Right-Rect.Left;
- R.Top :=Y;
- R.Bottom :=Y+Rect.Bottom-Rect.Top;
- // Dessin d'une partie de l'image
- CopyRect(Rect,BitMap.Canvas,R);
- Brush.Style := bsClear;
- End;
- // Sélection de la couleur de texte
- If gdSelected In State Then SetTextColor(Canvas.Handle,clRed)
- Else If gdFixed In State Then SetTextColor(Canvas.Handle,clBlack)
- Else SetTextColor(Canvas.Handle,clWhite);
- // Dessin du texte en utilisant la fonction API
- DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
- DT_CENTER Or DT_VCENTER Or DT_NOPREFIX Or DT_SINGLELINE);
- End;
- End;
-
Procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
Var i,x,y:Integer;
R:TRect;
Begin
With Sender As TStringGrid Do With Canvas Do
Begin
If gdFixed In State
Then Begin
// Les cellules fixes sont toujours dessinées en gris
Brush.Color := clBtnFace;
Brush.Style := bsSolid;
FillRect(Rect);
End
Else If gdSelected In State
Then Begin
// Les cellules sélectionnées sont en bleue
Brush.Color := clNavy;
Brush.Style := bsSolid;
FillRect(Rect);
End
Else Begin
// Recherche de la zone image à copier pour tenir compte des décalages
// de la grille en fonction des barres de défilement.
X:=0; For i:=FixedCols+1 To ACol Do Inc(x,ColWidths [i]);
Y:=0; For i:=FixedRows+1 To ARow Do Inc(Y,RowHeights[i]);
R.Left :=X;
R.Right :=X+Rect.Right-Rect.Left;
R.Top :=Y;
R.Bottom :=Y+Rect.Bottom-Rect.Top;
// Dessin d'une partie de l'image
CopyRect(Rect,BitMap.Canvas,R);
Brush.Style := bsClear;
End;
// Sélection de la couleur de texte
If gdSelected In State Then SetTextColor(Canvas.Handle,clRed)
Else If gdFixed In State Then SetTextColor(Canvas.Handle,clBlack)
Else SetTextColor(Canvas.Handle,clWhite);
// Dessin du texte en utilisant la fonction API
DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
DT_CENTER Or DT_VCENTER Or DT_NOPREFIX Or DT_SINGLELINE);
End;
End;