[教学] Firemonkey 之 StringGrid Header 自订显示
Posted 龟山Aone
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[教学] Firemonkey 之 StringGrid Header 自订显示相关的知识,希望对你有一定的参考价值。
StringGrid Header 高度设定方法:
uses FMX.Header; procedure TForm1.StringGrid1ApplyStyleLookup(Sender: TObject); var Obj: TFmxObject; begin // by Aone Obj := StringGrid1.FindStyleResource(‘header‘); if (Obj <> nil) and (Obj is THeader) then THeader(Obj).Size.Height := 50; // 设定高度 end;
ps. 所有的 Style 都能用这个方法,找到后,再修改它。
StringGrid Header 文字颜色设定方法(不改变底色):
procedure TForm1.StringGrid1DrawColumnHeader(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF); var Str: String; begin if Column = StringColumn1 then begin Str := ‘表头1‘; Canvas.Fill.Color := claBlue; end; if Column = StringColumn2 then begin Str := ‘表头2‘; Canvas.Fill.Color := claRed; end; Canvas.FillText(Bounds, Str, False, 1, [], TTextAlign.Center, TTextAlign.Center); end;
效果:
StringGrid Header 文字颜色设定方法(改变底色):
procedure TForm1.StringGrid1DrawColumnHeader(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF); var Str: String; BackColor, FontColor: TAlphaColor; begin if Column = StringColumn1 then begin Str := ‘表头1‘; BackColor := claYellow; FontColor := claBlue; end; if Column = StringColumn2 then begin Str := ‘表头2‘; BackColor := claGold; FontColor := claRed; end; Canvas.Fill.Color := BackColor; Canvas.FillRect(Bounds, 0, 0, [], 1); Canvas.Fill.Color := FontColor; Canvas.FillText(Bounds, Str, False, 1, [], TTextAlign.Center, TTextAlign.Center); end;
效果:
以上是关于[教学] Firemonkey 之 StringGrid Header 自订显示的主要内容,如果未能解决你的问题,请参考以下文章