【发布时间】:2016-10-04 04:44:28
【问题描述】:
我想知道如何在 StringGrid 中的单元格中心设置文本(垂直和水平)...我正在使用 StringGrid 的画布。
我正在使用 Delphi,我想要最简单的方法...
谁能帮帮我?
【问题讨论】:
标签: delphi text alignment center stringgrid
我想知道如何在 StringGrid 中的单元格中心设置文本(垂直和水平)...我正在使用 StringGrid 的画布。
我正在使用 Delphi,我想要最简单的方法...
谁能帮帮我?
【问题讨论】:
标签: delphi text alignment center stringgrid
您可以使用具有一些格式化功能的 API 函数DrawText。
简单示例:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
Grid: TStringGrid;
begin
Grid := Sender as TStringGrid;
Grid.Canvas.FillRect(Rect);
DrawText(Grid.Canvas.Handle, Grid.Cells[ACol, ARow],
Length(Grid.Cells[ACol, ARow]),
Rect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end;
【讨论】: