Lea*_*Lea 1 delphi header firemonkey stringgrid delphi-xe7
我在 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;
Run Code Online (Sandbox Code Playgroud)
我希望你们中的一些人能够理解这段代码的作用...这张图片可能会有所帮助。
我现在的问题是:如何设置标题以及如何放大标题的字体大小,或者 - 如果不可能 - 如何禁用、删除或隐藏标题?
提前致谢!
问候莉亚
简单的方法:您可以通过在设计时取消选中 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;
Run Code Online (Sandbox Code Playgroud)
在设计时编辑列标题文本,方法是右键单击 StringGrid 并选择“项目编辑器”。选择任意列并在对象检查器中设置标题属性。
或者,在运行时:sg1.Columns[zero_based_column_index].Header:='some text';
最后一个问题 - 如何设置标题高度...我不知道如何在运行时执行此操作。TStringGrid 和 TCustomGrid 使用私有字段 FHeader,它TCustomGrid.UpdateHeader通过从列复制值来更新方法。没有属性、事件或方法可以从 FMX.Grid 单元外部访问 FHeader...但您仍然可以自定义样式。只需在样式编辑器中选择 stringgridstyle.background.header 并在对象检查器中编辑 Height 属性即可。