敬业的IT人 >> 编程开发 >> Delphi >> 在stringgrid控件中使文字内容在cell中做到上下居中

在stringgrid控件中使文字内容在cell中做到上下居中

敬业的IT人 互联网 佚名 2008-1-4 15:39:42
在stringgrid控件中使文字内容在cell中做到上下居中
Seaspide 2001.4.19

经多次实践,偶终于找到了解决使文字内容在每个cell单元中上下居中的办法:
就是利用画板的draw方法,通过“画”出文字解决了这个问题。哈,不算是旁门左道吧~
实现非常简单:

设一全句变量: var Iscentre:boolean;

在需要上下居中显示文字内容时,用语句:
cells[x,y]:=', 并置Iscentre为真;
(注意:一定要赋空值!! 原因见下) ~~~~~x,y为局部变量

给Form1上的stringgrid控件添加OnDrawCell事件,过程代码:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if iscentre then
stringgrid1.Canvas.TextOut(rect.left 14,rect.top 8,'标题居中' );
end; ~~~~~~~~~~~~~~~~~~~~~~~~~
请根据具体设置调节!

因为此事件被触发的条件,是发生cell被赋值时, 所以必须先将其置空值以触发Stringgrid
的onDrawCell事件!
粤ICP备06119539号
Copyright CiscoSky.Org,Some Rights Reserved.
Email:me1228#tom.com