Here is the code I'm using. It was drawn from the older DrawCell event in a previous version of the program, so I expect I've coded something incorrectly, but not sure what.
procedure TfrmTimeOffList.grdRecListCellBeforeDraw(Sender: TObject; ACol,
ARow: Integer; AGraphics: TTMSFNCGraphics; var ARect, ATextRect: TRectF;
var ADrawText, ADrawBackGround, ADrawBorder, AllowDraw: Boolean);
var
TempString: string;
i,
TextWide: integer;
begin
inherited;
if ARow = 0 then
Exit;
TempString := grdRecList.Cells[ACol,ARow];
{ check the hours column for proper formatting }
if ACol = 2 then begin
grdRecList.Canvas.Font.Style := [];
{ use red if negative hours are entered }
if StrToFloat(TempString) < 0 then
grdRecList.Canvas.Fill.Color := TAlphaColorRec.Red;
{ bold the hours if negative hours are entered }
if (TempString > '') and (StrToFloat(TempString) < 0) then
grdRecList.Canvas.Font.Style := [TFontStyle.fsBold];
end
else begin
{ add the global image if the entry is a Global Time Off entry }
if (Pos('G',grdRecList.Cells[3,ARow]) > 0) and (ACol = 1) then begin
AGraphics.DrawBitmap(ATextRect.Left, ATextRect.Top +1,
ATextRect.Left + imgGlobal.Bitmap.Width,
imgGlobal.Bitmap.Height, imgGlobal.Bitmap);
ATextRect.Left := ATextRect.Left + imgGlobal.Bitmap.Width + 2;
end;
{ add the note image if the entry contains a comment }
if (Pos('*',grdRecList.Cells[3,ARow]) > 0) and (ACol = 1) then begin
TextWide := Trunc(grdRecList.Canvas.TextWidth(TempString)) + 2;
{ if the column is too narrow, truncate the Reason string }
if ATextRect.Right - ATextRect.Left < TextWide + imgNote.Bitmap.Width then begin
i := Length(TempString);
while ((TextWide + imgNote.Bitmap.Width) > (ATextRect.Right - ATextRect.Left))
and (i > 0) do begin
TempString := Copy(TempString,1,i);
Dec(i);
TextWide := Trunc(grdRecList.Canvas.TextWidth(TempString + '...'));
end;
TempString := TempString + '...';
AGraphics.DrawText(ATextRect, TempString);
end
else begin
AGraphics.DrawText(ATextRect, TempString);
end;
ATextRect.Left := ATextRect.Left + grdRecList.Canvas.TextWidth(TempString) + 2;
AGraphics.DrawBitmap(ARect.Left, ARect.Top, ARect.Left + imgNote.Bitmap.Width,
imgNote.Bitmap.Height, imgNote.Bitmap);
end;
end;
end;