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 都能用這個方法,找到後,再修改它。
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;
效果:
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;
效果: