如何将stringgrid中的内容对齐显示

shushan 2000-08-17 12:24:00
向各位大虾请教,如何将stringgrid中的内容对齐。
...全文
196 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shushan 2000-08-18
  • 打赏
  • 举报
回复
怎么没有人回答???
渤海海峡 2000-08-18
  • 打赏
  • 举报
回复
下载一个支持对齐的stringgrid不就行了。
http://www.hoerstemeier.com/index.htm
lotto 2000-08-18
  • 打赏
  • 举报
回复
在TStringGrid中的OnDrawCell事件中:
Procedure TForm1.StringGrid1DrawCell event (Sender: TObject; Col, Row: Integer;Rect: TRect; State: TGridDrawState);
var
A1,A2,width,height: integer;
str: string;
begin
Str := StringGrid1.Cells[col,row];
Width := StringGrid1.Canvas.textwidth(Str);
Height := StringGrid1.Canvas.textheight(Str);

if (Row = 0) then //固定Cell
begin
A1 := 0; //左对齐
end
else //其他的Cel
A1 := (StringGrid1.Colwidths[Col] - width-2);//右对齐

A2 := (StringGrid1.Rowheights[Row] - height) div 2;

if gdFixed in state then
StringGrid1.Canvas.Brush.Color := ClSilver //设置颜色
else
StringGrid1.Canvas.Brush.Color := ClWhite;

StringGrid1.Canvas.Font.Color := StringGrid1.Font.Color;
StringGrid1.Canvas.textrect(Rect,Rect.left+A1,Rect.Top+A2,StringGrid1.Cells[Col,Row]);
end;


--------------------------------------------------------------------------------
dit 2000-08-18
  • 打赏
  • 举报
回复
用 OnDrawCell 事件

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧