如何更改 Delphi TStringGrid 中固定行单元格中的文本方向
我在表单上有一个标准的 TStringGrid。 我在网格中有一个固定行,其中包含许多列,这些列都是 TGridColumns 对象。我已经使用对象检查器设置了列标题,默认方向是水平的。有什么方法可以使方向垂直(就像在 Excel 中的单元格中一样)?
I have a standard TStringGrid on a form.
I have one Fixed Row in the grid that contains a number of columns, which are all TGridColumns objects. I have set the column titles using the object inspector and the default orientation is horizontal. Is there any way you can make the orientation vertical (like you can in cells in Excel)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是如何在 Lazarus 中垂直渲染第一行文本:
以下是如何渲染
TStringGrid
在 Delphi 中垂直:我更喜欢使用重写的
DrawCell
过程,因为在我看来它是最简单的方法,因为如果您想简单地在OnDrawCell
事件那么您应该考虑:DefaultDrawing
设置为True
那么当OnDrawCell
事件被触发,所以这里我建议例如存储单独变量中的单元格标题,而不是Cells
属性,这样就不会渲染任何文本,DefaultDrawing
设置为False
那么你必须通过以下方式绘制整个单元格你自己的,包括 3D 边框,恕我直言,不是那么酷,我个人更喜欢让控件为我们绘制背景这是使用重写的
DrawCell
过程。文本在单元格矩形内部居中;请注意,我没有使用DrawTextEx
用于文本大小测量,因为此函数不考虑更改的字体方向。它的样子如下:
Here's how to render the first row's text vertically in Lazarus:
Here's how to render the first row's text of the
TStringGrid
vertically in Delphi:I would prefer to use the overriden
DrawCell
procedure because it seems to me as the easiest way to go because if you want to render the text simply in theOnDrawCell
event then you should consider:DefaultDrawing
set toTrue
then the text will already be rendered when theOnDrawCell
event is fired, so here I would recommend e.g. to store the cell captions in a separate variable, not intoCells
property so then no text will be rendered and you can draw your own stored captions verticallyDefaultDrawing
set toFalse
then you'll have to draw the whole cell by your own, including the 3D border, what is IMHO not so cool, and I would personally prefer to let the control draw the background for usHere is the Delphi code which uses the overriden
DrawCell
procedure. The text is being centered inside of the cell rectangle; please note that I haven't used theDrawTextEx
for text size measurement because this function doesn't take the changed font orientation into account.And here's how it looks like: