【发布时间】:2016-11-15 09:47:07
【问题描述】:
我使用drawstring方法在矩形内绘制文本,..我想将文本旋转180度所以我使用了这个代码
Rectangle displayRectangleh =
new Rectangle(new Point((int)posh.X, (int)posh.Y), new Size(rectwdh, recth));
StringFormat format1h = new StringFormat(StringFormatFlags.DirectionVertical);
format1h.LineAlignment = StringAlignment.Center;
format1h.Alignment = StringAlignment.Center;
b = new SolidBrush(Color.Black);
e.ChartGraphics.Graphics.TranslateTransform((float)rectwdh / 2 + posh.X, recth / 2 + posh.Y);
e.ChartGraphics.Graphics.RotateTransform(180);
e.ChartGraphics.Graphics.TranslateTransform(-((float)rectwdh / 2 + posh.X), -(recth / 2 + posh.Y));
Font boldFonth = new Font(FontFamily.GenericSansSerif, 16, FontStyle.Bold, GraphicsUnit.Pixel, 1, true);
e.ChartGraphics.Graphics.DrawRectangle(new Pen(Color.Black, 2), displayRectangleh);
e.ChartGraphics.Graphics.DrawString("This is rotated long text test ", boldFonth, b, (RectangleF)displayRectangleh, format1h);
e.ChartGraphics.Graphics.ResetTransform();
其中 posh.X 和 posh.Y(重新排列位置)、rectwdh(矩形宽度)和 recth(矩形高度)
它非常适合短文本,但对于长文本,新行将在我的旧行上方,请参见下一张图片:
我什至尝试添加换行符 \n 但结果相同。 我的问题:如何在矩形内旋转文本 180 并以正确对齐结束??
【问题讨论】:
标签: c# winforms drawstring