如何在StringGrid单元格中显示多行文本(Delphi XE6-Android)
我有一个数据库绑定到Firemonkey StringGrid,我想为Android应用程序在单元格中显示一个长文本字段,但我找不到这样做的属性或过程。有什么想法吗?(谢谢)我在这个链接上找到了这个问题的部分解决方案: 在STringGrid的OnDrawColumnCell事件中(对原始事件稍作修改),输入以下代码:如何在StringGrid单元格中显示多行文本(Delphi XE6-Android),delphi,cell,firemonkey,multiline,stringgrid,Delphi,Cell,Firemonkey,Multiline,Stringgrid,我有一个数据库绑定到Firemonkey StringGrid,我想为Android应用程序在单元格中显示一个长文本字段,但我找不到这样做的属性或过程。有什么想法吗?(谢谢)我在这个链接上找到了这个问题的部分解决方案: 在STringGrid的OnDrawColumnCell事件中(对原始事件稍作修改),输入以下代码: procedure TForm1.StringGrid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas; const
procedure TForm1.StringGrid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF; const Row: Integer; const Value: TValue; const State: TGridDrawStates);
const
HorzTextMargin = 2;
VertTextMargin = 1;
var
TextLayout : TTextLayout;
TextRect: TRectF;
begin
// Here we determine which cell will redraw
if (Column.Index=0) then
begin
TextRect := Bounds;
TextRect.Inflate(-HorzTextMargin, -VertTextMargin);
Canvas.FillRect(Bounds, 0, 0, AllCorners, 1);
TextLayout := TTextLayoutManager.DefaultTextLayout.Create;
try
TextLayout.BeginUpdate;
try
TextLayout.WordWrap := True; // True for Multiline text
TextLayout.Opacity := Column.AbsoluteOpacity;
TextLayout.HorizontalAlign := StringGrid1.TextSettings.HorzAlign;
TextLayout.VerticalAlign := StringGrid1.TextSettings.VertAlign;
TextLayout.Trimming := TTextTrimming.Character;
TextLayout.TopLeft := TextRect.TopLeft;
TextLayout.Text := Value.ToString;
TextLayout.MaxSize := PointF(TextRect.Width, TextRect.Height);
{ Custom settings rendering }
TextLayout.Font.Family := 'Times New Roman';
TextLayout.Font.Style := [ TFontStyle.fsBold ];
TextLayout.Font.Size := 14;
TextLayout.Color := claBlueViolet;
finally
TextLayout.EndUpdate;
end;
TextLayout.RenderLayout(Canvas);
finally
TextLayout.Free;
end;
end;
end;
我们需要添加“Uses FMX.TextLayout;”对于颜色的常量,请单击窗体和“System.UIConsts”
要查看多行文字,当然需要在StringGrid的RowHeight属性中使用更大的数字 这也可以用于WIN32上的VCL吗?