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
| procedure TForm1.Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF; const Row: Integer;
const Value: TValue; const State: TGridDrawStates);
var ATextLayout : TTextLayout;
h : single;
function GetTextHeight(const L: TTextLayout; const Width: single; const
Text: string): Integer;
var
Layout: TTextLayout;
begin
Layout := TTextLayoutManager.DefaultTextLayout.Create;
try
Layout.BeginUpdate;
try
Layout.Font.Assign(L.Font);
Layout.VerticalAlign := TTextAlign.Leading;
Layout.HorizontalAlign := TTextAlign.Leading;
Layout.WordWrap := True;
Layout.Trimming := TTextTrimming.Word;
Layout.MaxSize := TPointF.Create(Width,
TTextLayout.MaxLayoutSize.Y);
Layout.Text := Text;
finally
Layout.EndUpdate;
end;
Result := Round(Layout.Height);
Layout.Text := 'm';
Result := Result + Round(Layout.Height);
finally
Layout.Free;
end;
end;
begin
if SameText(Column.Header,'notes') then
begin
h:=GetTextHeight(Column.Layout,column.AbsoluteWidth,Value.ToString);
if h>Grid1.RowHeight then Grid1.RowHeight:=h; // au plus grand
ATextLayout:=TTextLayoutManager.TextLayoutByCanvas(Canvas.ClassType).Create(Canvas);
ATextLayout.BeginUpdate;
ATextLayout.Text:=Value.ToString;
ATextLayout.Color:=TAlphaColors.Black;
ATextLayout.TopLeft:=Bounds.TopLeft;
ATextLayout.MaxSize := PointF(Bounds.Width, h);
ATextLayout.WordWrap:=true;
ATextLayout.VerticalAlign:=TTextAlign.Leading;
ATextLayout.EndUpdate;
ATextLayout.RenderLayout(Canvas);
end
else Column.DefaultDrawCell(Canvas,bounds,row,value,state);
end; |
Partager