Using a TMSFNCGrid (version 1.1.0.5) in Delphi Athens in a VCL application. I'm trying to draw multiple lines of text in a cell by parsing the text assigned to the cell. Each row in the grid may be a different height depending on how many lines are in a cell. Text in the cell may be different colors as well. (Entries in the grid represent who took time off from work on that day - the grid shows then entire month.)
Here is the code I've tried, but it does not seem to draw the text in separate lines:
procedure TfrmMonthCalendar.grdCalendarCellBeforeDraw(Sender: TObject; ACol,
ARow: Integer; AGraphics: TTMSFNCGraphics; var ARect, ATextRect: TRectF;
var ADrawText, ADrawBackGround, ADrawBorder, AllowDraw: Boolean);
var
Entry,
EntryList: string;
X1, X2, Y1, Y2: integer;
ctr,
idx: integer;
// TmpRect,
Rect: TRect;
TextWide: integer;
begin
if ARow = 0 then
Exit;
if grdRecList.Cells[ACol,ARow] = '' then
Exit;
Rect := TRect.Create(Trunc(ATextRect.Left), Trunc(ATextRect.Top),
Trunc(ATextRect.Right), Trunc(ATextRect.Bottom));
ADrawText := False;
EntryList := grdRecList.Cells[ACol,ARow];
idx := pos('|',EntryList);
ctr := 0;
while idx > 0 do begin
Entry := copy(EntryList,1,idx-1);
if ctr = 0 then begin
AGraphics.Canvas.Font.Style := [TFontStyle.fsBold];
AGraphics.Canvas.Font.Color := clBlack;
end
else begin
AGraphics.Canvas.Font.Style := {};
AGraphics.Canvas.Font.Color := TIDRecClass(fGridRecs[ACol,ARow][ctr]).IDNum;
end;
AGraphics.DrawText(Rect, Entry);
EntryList := copy(EntryList,idx+1,length(EntryList));
Rect.Top := Rect.Top + PixelAdj(13);
idx := pos('|',EntryList);
inc(ctr);
end;
if grdRecList.RowHeights[ARow] < Rect.Top then
grdRecList.RowHeights[ARow] := Rect.Top;
end;
I've also attached an image of what I'm trying to accomplish if my description isn't clear enough.