delphi - 如何更改 Delphi Firemonkey XE7 中 Stringgrid 标题的字体大小?

标签 delphi header firemonkey delphi-xe7 stringgrid

我在 Delphi Firemonkey XE7 中为应用程序创建了一个 Stringgrid,并用我的 MySQL 数据库中的数据填充它。 为了放大字体大小,我使用了以下代码:

procedure TFormSearchRecipient.sgRecipientDrawColumnCell(Sender: TObject;
  const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
  const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var b : TRectF; border: integer;
begin
  //following leaves in the end a border so that the marked item can be seen
  b := bounds;
  border:= 2;
  b.Top := b.Top + border;
  b.Left := b.Left - border;
  b.Height := b.Height - 2 * border;
  b.Width := b.Width - 2 * border;

  //colors the background white so that the data cannot be seen anymore
  Canvas.Fill.Color := TAlphaColorRec.White;
  Canvas.FillRect(b, 0, 0, [], 1);
  //change the canvas text options
  Canvas.Fill.Color := TAlphaColorRec.Black;
  Canvas.Font.Size := 25;
  //write the content
  Canvas.FillText(Bounds, Value.AsString , False, 1, [] , TTextAlign.Leading);
end;

我希望你们中的一些人能够理解这段代码的作用...... 这个picture可能有帮助。

我现在的问题是:如何设置标题以及如何放大标题的字体大小,或者 - 如果不可能 - 如何禁用、删除或隐藏标题?

提前致谢!

问候莉亚

最佳答案

简单的方法:您可以通过在设计时取消选中 StringGrid.Options 中的选项 Header 来隐藏标题。

或者,在运行时:StringGrid.Options:=StringGrid.Options - [TGridOption.Header]

对于绘制标题文本,您可以使用 OnDrawColumnHeader 事件。例如:

procedure THeaderFooterForm.sg1DrawColumnHeader(Sender: TObject;
  const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF);
begin
  Canvas.Fill.Color := TAlphaColorRec.White;
  Canvas.FillRect(Bounds, 0, 0, [], 1);
  Canvas.Font.Size := 25;
  Canvas.Fill.Color := TAlphaColorRec.Black;
  Canvas.FillText(Bounds, Column.Header , False, 1, [] , TTextAlign.Leading);
end;

在设计时编辑列标题文本,方法是右键单击 StringGrid 并选择“项目编辑器”。选择任意列并在对象检查器中设置标题属性。

或者,在运行时:sg1.Columns[zero_based_column_index].Header:='some text';

最后一个问题 - 如何设置标题高度...我不知道如何在运行时执行此操作。 TStringGrid 和 TCustomGrid 使用私有(private)字段 FHeader,它通过从列复制值在 TCustomGrid.UpdateHeader 方法中进行更新。没有属性、事件或方法可以从 FMX.Grid 单元外部访问 FHeader... 但您仍然可以自定义样式。只需在样式编辑器中选择 stringgridstyle.background.header 并在对象检查器中编辑 Height 属性即可。

关于delphi - 如何更改 Delphi Firemonkey XE7 中 Stringgrid 标题的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31704675/

相关文章:

c - 头文件中的全局结构

iOS 火猴 : How to send email from iOS App though mail app in Firemonkey Delphi XE7

delphi - 在表单中实时绑定(bind)现有的用户对象

delphi - EInsufficientRTTI 异常,消息 'Insufficient RTTi available to support this operation'

delphi - 如何将我的发布者名称添加到我的 delphi exe 程序中?

delphi - 有条件地编译 FMX 或 VCL 单元

android - FMXBroadcastReceiver (Android) 在 Delphi 10 Seattle 中损坏了吗?自 XE7 以来发生了什么变化?

android - iOS/Android 与 Delphi/C# 桌面应用程序同步

c++ - C++ 程序中的 C 头文件

c++ - 我应该包括 <tuple> 吗?