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
| //------------------------------------------------------------------------------
procedure TDBGridSLTAssistant.DrawTextWithBackgroundColor(ABackgroundColor: TColor; const ARect: TRect; AColumn: TColumn; AState: TGridDrawState);
var
vText: string;
vRect: TRect;
begin
with DBGrid.Canvas do
begin
// Force un fond opaque pour cacher le texte !
Brush.Style := bsSolid;
Brush.Color := ColorToRGB(ABackgroundColor);
FillRect(ARect);
// TextRect encapsule DraxTextEx et est aussi pénible avec ses paramètres in-out !
vRect := ARect;
if Assigned(AColumn.Field) then
vText := AColumn.Field.DisplayText;
Font.Color := TCanvasSLTAssistant.GetConstratedColor(ABackgroundColor); // Couleur de luminosité inverse : Contraste garanti pour les couleurs claires ou foncées
// Gestion de l'Alignment corrigé selon de Vcl.DBGrids.WriteText
// DT_CENTER Centers text horizontally in the rectangle.
// DT_VCENTER Centers text vertically. This value is used only with the DT_SINGLELINE value.
if AColumn.Alignment = taLeftJustify then
TextRect(vRect, vRect.Left + 3, vRect.Top + 2, vText)
else if AColumn.Alignment = taCenter then
TextRect(vRect, vText, [tfCenter, tfSingleLine, tfVerticalCenter])
else
begin
vRect.Right := vRect.Right - 3;
TextRect(vRect, vText, [tfRight, tfSingleLine, tfVerticalCenter]);
end;
if (gdRowSelected in AState) or ((dgRowSelect in DBGrid.Options) and (gdSelected in AState)) then
begin
// Pour ne pas dessiner les bords de focus entre les colonnes (inspiré des tricheries dans TCustomGrid.DrawCellHighlight)
vRect := ARect;
InflateRect(vRect, 1, 0);
DrawFocusRect(vRect);
end
else
if gdSelected in AState then
DrawFocusRect(vRect);
end;
end; |
Partager