简体   繁体   English

如何在StringGrid单元格中显示多行文本(Delphi XE6-Android)

[英]How to display a multiline text in a StringGrid Cell (Delphi XE6 - Android)

I have a database bind to a Firemonkey StringGrid and I want to show a long text field in the cells, for an Android App, but I can't find a property nor procedure to do that. 我有一个数据库绑定到Firemonkey StringGrid,并且想在一个Android应用程序的单元格中显示一个长文本字段,但是我找不到执行此操作的属性或过程。 Any idea? 任何想法? (Thanks) (谢谢)

I've found a partial solution to this issue at this link: 我在以下链接中找到了针对此问题的部分解决方案:

http://fire-monkey.ru/topic/287-izmenenie-svoistva-shrifta-odnoi-iacheiki-v-firemonkey-tstringgrid-delphi-xe6/#entry1041 http://fire-monkey.ru/topic/287-izmenenie-svoistva-shrifta-odnoi-iacheiki-v-firemonkey-tstringgrid-delphi-xe6/#entry1041

In the STringGrid's OnDrawColumnCell event (with a little modifications from the original), put this code: 在STringGrid的OnDrawColumnCell事件中(对原始事件进行一些修改),输入以下代码:

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;

We need to add 'Uses FMX.TextLayout;' 我们需要添加“ Uses FMX.TextLayout;” to the form and 'System.UIConsts' for the color's constants. 形式和'System.UIConsts'表示颜色的常量。

To see a multiline text, of course we need to use a bigger number in the StringGrid's RowHeight property. 要查看多行文本,我们当然需要在StringGrid的RowHeight属性中使用更大的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM