C# Graphics DrawString VerticalDirection 从底部开始
我需要在打印文档方法中使用 Graphics.DrawString 编写一个垂直方向的字符串,并且我对字符串宽度有限制,问题是字符串是从左到右编写的,我需要第一行在右边我正在使用下面的方法
SizeF s = e.Graphics.MeasureString(str1, po.defaultF,la1, StringFormat.GenericTypographic);
RectangleF rec=new RectangleF();
StringFormat strF=new StringFormat();
strF.FormatFlags=StringFormatFlags.DirectionVertical;
rec.Height=s.Width+15;
rec.Width=s.Height+5;
rec.X =0;
rec.Y=0;
e.Graphics.DrawString(str1, po.defaultF, Brushes.Black, rec, strF);
I need to write using Graphics.DrawString in a print Document method , a string with vertical direction and I have a limitation on the string width , the problem is that the string is writen from left to right and I need that the first line be on the right I'm using the method below
SizeF s = e.Graphics.MeasureString(str1, po.defaultF,la1, StringFormat.GenericTypographic);
RectangleF rec=new RectangleF();
StringFormat strF=new StringFormat();
strF.FormatFlags=StringFormatFlags.DirectionVertical;
rec.Height=s.Width+15;
rec.Width=s.Height+5;
rec.X =0;
rec.Y=0;
e.Graphics.DrawString(str1, po.defaultF, Brushes.Black, rec, strF);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Hans 评论的那样,
RotateTransform
可用于翻转字符串:TranslateTransform 将坐标系的原点更改为
rec
矩形的右下角,然后RotateTransform
翻转它180 度,然后将字符串的对齐方式更改为“远”,将字符串放置到原始字符串绘制的同一位置。As Hans' commented, the
RotateTransform
can be used to flip the string around:The TranslateTransform changes the origin of your coordinate system to the bottom right corner of your
rec
rectangle, then theRotateTransform
flips it 180 degrees, and then the alignment of the string is changed to Far to place the string into the same place your original string was drawing.您应该查看以下示例:
http:// msdn.microsoft.com/en-us/library/aa287525%28v=vs.71%29.aspx
它应该完全符合您的要求。
编辑:
从右向左绘制可能是愚蠢的方式:
You should look at this example:
http://msdn.microsoft.com/en-us/library/aa287525%28v=vs.71%29.aspx
It should do exactly what you're asking.
EDIT:
Possibly stupid way of drawing from right to left:
解决方案是使用 RotateTransform(90) 并且不使用 StringFormatFlags.DirectionVertical
这是代码的和平:
The solution is to use RotateTransform(90) and without using the StringFormatFlags.DirectionVertical
here is the peace of code:
我改编了 @LarsTech 答案中的代码片段,它对我有用,如下所示:
文本将被绘制,就像从下到上书写一样,左对齐。
I adapted the code snippet from @LarsTech's answer and it worked for me as below:
The text will be drawn as if it is written from bottom to top, left-aligned.