procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
Str: String;
R: TRect;
begin
with StringGrid1 do
begin
Canvas.FillRect(Rect);
Str := Cells[ACol,ARow];
R := Rect;
DrawText(Canvas.Handle,PChar(Str),Length(Str),r,DT_CENTER or DT_SINGLELINE or DT_VCENTER); //文字居中
end;
end;
StringGrid文字居中
本文介绍了一种使用Delphi在StringGrid中实现单元格内文本居中的方法。通过自定义DrawCell过程,利用DrawText函数实现了文本的水平及垂直居中显示,提升了表格的视觉效果。

被折叠的 条评论
为什么被折叠?



