1

我有一个绑定到 Firemonkey StringGrid 的数据库,我想在单元格中显示一个长文本字段,用于 Android 应用程序,但我找不到执行此操作的属性或过程。任何想法?(谢谢)

4

1 回答 1

2

我在这个链接上找到了这个问题的部分解决方案:

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

在 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;

我们需要添加“使用 FMX.TextLayout;” 颜色常量的表单和“System.UIConsts”。

要查看多行文本,我们当然需要在 StringGrid 的 RowHeight 属性中使用更大的数字。

于 2014-11-19T03:49:52.797 回答