在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事件!
|