C# Graphics DrawString VerticalDirection 从底部开始 [英] C# Graphics DrawString VerticalDirection start from the bottom

查看:58
本文介绍了C# Graphics DrawString VerticalDirection 从底部开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在打印文档方法中使用 Graphics.DrawString 编写一个垂直方向的字符串,并且我对字符串宽度有限制,问题是字符串是从左到右写入的,我需要第一个线在右边我正在使用下面的方法

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);

推荐答案

解决方案是使用 RotateTransform(90) 而不使用 StringFormatFlags.DirectionVertical这是代码的和平:

The solution is to use RotateTransform(90) and without using the StringFormatFlags.DirectionVertical here is the peace of code:

Rectangle rec = new Rectangle();
rec.Height = 2 * po.medF.Height;
rec.Width=100;
rec.X = 0;
rec.Y = 0;
SizeF s;
String str = "your Text";
StringFormat strf = new StringFormat();
strf.Alignment = StringAlignment.Center;    
rec.X = 0;
rec.Y = 0;
e.Graphics.TranslateTransform(X1, Y1);
e.Graphics.RotateTransform(90);
e.Graphics.DrawString(str, po.medF, Brushes.Black, rec, strf);
e.Graphics.ResetTransform();

这篇关于C# Graphics DrawString VerticalDirection 从底部开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆