掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
Delphi FMX StringGrid 枠線 (ID:151873)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
Androidではなく、Windowsで試したのですが・・ const TEST_COL = 20; TEST_ROW = 80; // FormCreate procedure TForm1.FormCreate(Sender: TObject); var sCol: TStringColumn; c, r: Integer; begin // 線と文字列の描画は、OnDrawColumnCellイベント・OnDrawColumnBackgroundイベントにて行うので、 // いくつか設定を変更。 StringGrid1.DefaultDrawing := False; StringGrid1.Options := StringGrid1.Options - [TGridOption.ColLines, TGridOption.RowLines]; // StringGrid初期値設定 with StringGrid1 do begin BeginUpdate; for c := 1 to TEST_COL do begin sCol := TStringColumn.Create(StringGrid1); sCol.Name := 'col' + IntToStr(c); sCol.Header := 'テスト' + IntToStr(c); sCol.Width := 80; AddObject(sCol); end; EndUpdate; RowCount := TEST_ROW; for r := 0 to RowCount - 1 do for c := 0 to ColumnCount - 1 do Cells[c, r] := Format('[%d, %d]', [c, r]); end; end; // StringGrid1:DrawColumnBackgroundイベント procedure TForm1.StringGrid1DrawColumnBackground(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF; const Row: Integer; const Value: TValue; const State: TGridDrawStates); begin // 背景描画 if (Row mod 2) = 0 then Canvas.Fill.Color := TAlphaColorRec.White else Canvas.Fill.Color := TAlphaColorRec.Whitesmoke; Canvas.FillRect(Bounds, 0, 0, AllCorners, 1.0, TCornerType.Round); // 枠線描画 Canvas.Stroke.Kind := TBrushKind.Solid; Canvas.Stroke.Color := TAlphaColorRec.Black; Canvas.Stroke.Thickness := 1.0; // 縦線 Canvas.DrawLine(PointF(Bounds.Right, Bounds.Top), PointF(Bounds.Right, Bounds.Bottom), 1.0); // 横線 if (Row mod 5) = 4 then Canvas.Stroke.Color := TAlphaColorRec.Red; // 5行おきに線の色を赤に Canvas.DrawLine(PointF(Bounds.Left, Bounds.Bottom), PointF(Bounds.Right, Bounds.Bottom), 1.0); end; // StringGrid1:DrawColumnCellイベント procedure TForm1.StringGrid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF; const Row: Integer; const Value: TValue; const State: TGridDrawStates); begin // 文字描画 Canvas.Fill.Color := TAlphaColorRec.Blue; Canvas.FillText(Bounds, Trim(Value.AsString), True, 1.0, [], TTextAlign.Center, TTextAlign.Center); end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.