在c#中从左到右打印

| 根据msdn:http://www.microsoft.com/middleeast/msdn/arabicsupp.aspx   GDI +如何支持阿拉伯语?      GDI +支持阿拉伯语文本操作,包括针对输出设备(屏幕和打印机)的RTL阅读顺序的打印文本。 Graphics.DrawString方法使用指定StringFormat对象的格式设置属性,使用指定的Brush和Font对象在指定的x,y位置或矩形(根据其重载)绘制指定的文本字符串。 StringFormat对象包含文本布局信息,例如文本阅读顺序。      因此,您可以轻松地将图形对象的原点移动到“右上角”而不是“左上角”,以在屏幕上的指定位置平滑地打印出阿拉伯文本,而无需显式计算位置。 将(X,Y)坐标设置为(0,0)时确实如此,但是如果我想增加X坐标以在纸张的特定区域打印,X坐标将增加到纸张的右侧而不是从右到左打印时应保留的原样;这意味着可以在纸张外面打印。 观看此演示:
static void Main(string[] args)
{
    PrintDocument p = new PrintDocument();
    p.PrintPage += new PrintPageEventHandler(PrintPage);
    p.Print();
}

static void PrintPage(object sender, PrintPageEventArgs e)
{
    string drawString = \"إختبار الرسم\";
    SolidBrush drawBrush = new SolidBrush(Color.Black);
    Font drawFont = new System.Drawing.Font(\"Arail\", 16);
    RectangleF recAtZero = new RectangleF(0, 0, e.PageBounds.Width, e.PageBounds.Height);
    StringFormat drawFormat = new StringFormat();

    drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;

    e.Graphics.DrawString(drawString, drawFont, drawBrush, recAtZero, drawFormat);
    RectangleF recAtGreaterThantZero = new RectangleF(300, 0, e.PageBounds.Width, e.PageBounds.Height);
    e.Graphics.DrawString(drawString, drawFont, drawBrush, recAtGreaterThantZero, drawFormat);
}
如何将图形对象的原点移动到“右上角”而不是“左上角”,并且在增加X坐标时将打印点向左而不是向右推进。 PS:我现在正在做的就是将X坐标设置为负,以强制其向左移动。     
已邀请:
使用StringFormatFlags.DirectionRightToLeft,如下所示:
StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
e.Graphics.DrawString(\"سلام\",
                this.Font,
                new SolidBrush(Color.Red),
                r1,
                format);
    
您可以进行非常简单的坐标转换:
public static class CoordinateConverter
{
    public static RectangleF Convert(RectangleF source, RectangleF drawArea)
    {
        // I assume drawArea.X to be 0
        return new RectangleF(
            drawArea.Width - source.X - source.Width,
            source.Y,
            source.Width,
            source.Height);
    }

    public static RectangleF ConvertBack(Rectangle source, RectangleF drawArea)
    {
       return new RectangleF(
           source.X + source.Width - drawArea.Width,
           source.Y,
           source.Width,
           source.Height);
    }
}
现在,每次您想要绘制一些文本时,都可以使用此转换器更改坐标。当然,您也可以参考矩形,这样就不会一直创建新的矩形。但是原理保持不变。希望我能正确理解您的问题。     

要回复问题请先登录注册