StringGridのFontや大きさが変えれません。
VCLの場合、DrawCellで記述して実現していたのですが、
FMXの場合、よく分かりません。
ComboBoxやTListBoxでは、ListBox1.ListItems[i].Fontで
変更できるのですが・・・。
よろしくお願いします。
TTextCellを使ってください。
アライメント、色、Size、Style、フォントなど指定できます。
記述はOnPaintでいけるでしょう。
参考までに・・・
procedure TForm1.StringGrid1Paint(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
var
i,j :Integer;
begin
for i := 0 to StringGrid1.ColumnCount-1 do
begin
for j := 0 to StringGrid1.RowCount-1 do
begin
if Assigned(TTextCell(StringGrid1.Columns[i].CellControlByRow(j))) then
begin
with TTextCell(StringGrid1.Columns[i].CellControlByRow(j)) do
begin
if (i mod 2 = 0) and (j mod 2 = 0) then
begin
TextAlign := TTextAlign.taCenter;//アライメント
Font.Size := 16;
//FontFill.Color := claBlueViolet; {色}
//Font.Family := 'Times New Roman';{フォント}
//Font.Style := [ TFontStyle.fsBold ];{スタイル}
end else begin
TextAlign := TTextAlign.taLeading;
Font.Size := 11;
end;
end;
end;
end;
end;
end;
ありがとうございます。
教えて頂いてもらったのですが・・・。
サンプルソースを参考にやってみましたが、
ただ記述するだけでは駄目でした。
StringGridがフォーカスを受け取ったタイミング時にしか
反映されませんでした。
Buttonの処理で、VisibleをTrueにし、Realignしてもできなかったです。
FireMonkeyではすべてのセルに TTextCell(TEdit) が割り当てられます。
この各TTextCellを格納する配列が、
TColumn で protected FCellControls: array of TStyledControl;
として宣言されています。
要は、この FCellControls[] にアクセルできればよいわけですが、
方法が2つあります。
方法1
単純な StringGrid であれば、
StringGrid内 の 各StringColumn はそれぞれ、
Children[], ChildrenCount
Components[], ComponentCount のプロパティを持っていますが、
この Children[], Components[] に FCellControls[] がセットされます。
(ChildrenCount, ComponentCount は、StringGrid.RowCount)
以下コードを記述。
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringColumn1: TStringColumn;
procedure FormCreate(Sender: TObject);
private
{ private 宣言 }
public
{ public 宣言 }
end;
procedure TForm1.FormCreate(Sender: TObject);
{///////////////////////////////////////////////////////////////
FormCreate
///////////////////////////////////////////////////////////////}
var I: Integer;
begin
inherited;
with StringColumn1 do begin
for I := 0 to ComponentCount-1 do
if Components[I] is TTextCell then begin
TTextCell(Components[I]).Font.Family := 'メイリオ';
TTextCell(Components[I]).Font.Size := 14;
TTextCell(Components[I]).TextAlign := TTextAlign.taCenter;
end;
end;
end;
方法2
TStringColumn を新たに定義して FCellControls を可視化する。
type
TStringColumn = class(FMX.Grid.TStringColumn)
function GetCellControl(Index: Integer): TTextCell;
public
property CellControls[Index: Integer]: TTextCell
read GetCellControl;
end;
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringColumn1: TStringColumn;
private
{ private 宣言 }
public
{ public 宣言 }
end;
以下、省略。(忙しいので、あとは自分でお考えください)
ツイート | ![]() |