如何设置StringGrid单元格内容水平、垂直居中
时间:2011-12-20
来源:互联网
如何设置StringGrid单元格内容水平、垂直居中
作者: yuhong0725 发布时间: 2011-12-20
没有属性可以设置,只能自己画。比较麻烦
stringgrid可以用下面的方法,响应grid的 ondrawcell事件,在响应事件
里自己提供画表格中元素的方法,当然你就可以随便怎样定义它的对齐方式了。
一个例子:
//表格OnDrawCell事件方法
procedure TFormTest.StringGridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
const
WSpace = 2;
HSpace = 2;
var
tmpstr: string;
w,h: integer;
begin
if (Sender as TStringGrid).tag>0 then
begin
tmpstr := (Sender as TStringGrid).Cells[ACol,ARow];
with (Sender as TStringGrid).Canvas do
begin
w := TextWidth(tmpstr);
h := TextHeight(tmpstr);
if (gdFixed in State) then
TextRect(Rect,trunc((Rect.Right+Rect.Left-w)/2)+WSpace, //居中显示
trunc((Rect.Bottom+Rect.Top-H)/2)+HSpace,tmpstr)
else //右对齐显示
TextRect(Rect,Rect.Right-WSpace-W,Rect.Bottom-HSpace-H,tmpstr);
end;
end;
end;
从别的贴子拷贝过来的。看来你自己实在懒的动!就在CSDN上。
stringgrid可以用下面的方法,响应grid的 ondrawcell事件,在响应事件
里自己提供画表格中元素的方法,当然你就可以随便怎样定义它的对齐方式了。
一个例子:
//表格OnDrawCell事件方法
procedure TFormTest.StringGridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
const
WSpace = 2;
HSpace = 2;
var
tmpstr: string;
w,h: integer;
begin
if (Sender as TStringGrid).tag>0 then
begin
tmpstr := (Sender as TStringGrid).Cells[ACol,ARow];
with (Sender as TStringGrid).Canvas do
begin
w := TextWidth(tmpstr);
h := TextHeight(tmpstr);
if (gdFixed in State) then
TextRect(Rect,trunc((Rect.Right+Rect.Left-w)/2)+WSpace, //居中显示
trunc((Rect.Bottom+Rect.Top-H)/2)+HSpace,tmpstr)
else //右对齐显示
TextRect(Rect,Rect.Right-WSpace-W,Rect.Bottom-HSpace-H,tmpstr);
end;
end;
end;
从别的贴子拷贝过来的。看来你自己实在懒的动!就在CSDN上。
作者: nm_wyh 发布时间: 2011-12-20
http://topic.csdn.net/t/20031028/09/2401656.html
作者: ksrsoft 发布时间: 2011-12-20
http://blog.csdn.net/csdsym/article/details/3047678
作者: ksrsoft 发布时间: 2011-12-20
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28