2014-11-09 58 views

回答

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屬性中使用更大的數字。

+0

這也可以用於WIN32上的VCL嗎? – 2017-04-12 09:43:03

相關問題