我想在指定的矩形(垂直方向)中绘制一个字符串,下面的代码为我提供了扫描,但是文本流程是从左到右,我想要的是从右到左。与右侧的第1行相似,第2行在左侧。我也做了转型,但没有运气。
RectangleF tabbor = new RectangleF(0, 0,borHeight, 44.35F);
StringFormat sf = new StringFormat();
//if (cmbDir.SelectedItem.Equals("Vertical"))
// sf.FormatFlags = StringFormatFlags.DirectionVertical;
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
SolidBrush drawBrush = new SolidBrush(Color.Black);
//Do 180 degree Rotatation Transformation
ev.Graphics.RotateTransform(90, MatrixOrder.Append);
ev.Graphics.TranslateTransform(xPos+44.35F, yPos, MatrixOrder.Append);
ev.Graphics.DrawString("T", printFont, Brushes.Black, tabbor, sf);
if (cbPreview.Checked)
ev.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(tabbor));
我正在寻找从上到下的文本(现在是反向的),从右到左的行位置(这是有效的)
答案 0 :(得分:0)
您可以通过180度旋转变换来实现此目的。请检查以下代码
RectangleF tabbor = new RectangleF(0, 0, 44.35F,150.0F);
StringFormat sf = new StringFormat();
sf.FormatFlags = StringFormatFlags.DirectionVertical;
String drawString = "First Line Second Line";
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
float x = 0F;
float y = 0F;
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
//Do 180 degree Rotatation Transformation
ev.Graphics.RotateTransform(180,MatrixOrder.Append);
ev.Graphics.TranslateTransform(50, 150,MatrixOrder.Append);
ev.Graphics.DrawString(drawString, drawFont, Brushes.Black, tabbor,sf);
ev.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(tabbor));