1

我想在指定的矩形(垂直方向)中绘制一个字符串,下面的代码给了我我想要的,但文本流是从左到右,我想要的是从右到左。就像 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));

在此处输入图像描述我正在寻找从上到下的文本(现在它是反向的),从右到左的行位置(这是有效的)

在此处输入图像描述

4

1 回答 1

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)); 
于 2013-01-07T05:27:56.473 回答