在 C# 中从右到左打印 [英] Printing Right-To-Left in c#

查看:27
本文介绍了在 C# 中从右到左打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据msdn:http://www.microsoft.com/middleeast/msdn/arabicsupp.aspx

GDI+ 如何支持阿拉伯语?

How GDI+ Support Arabic?

GDI+ 支持阿拉伯语文本操作,包括使用 RTL 阅读顺序打印文本,用于输出设备、屏幕和打印机.Graphics.DrawString 方法在指定的 x、y 位置或矩形(根据其重载)绘制指定的文本字符串,指定的 Brush 和 Font 对象使用指定的 StringFormat 对象的格式设置属性.StringFormat 对象包括文本布局信息,例如文本阅读顺序.

GDI+ supports Arabic text manipulation including print text with RTL reading order for both output devices, Screen and Printer. The Graphics.DrawString method draws the specified text string at a designated x, y location or rectangle (according to its overloading), with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object. The StringFormat object includes text layout information such as text reading order.

因此,您可以轻松地将图形对象的原点移动到 Right-Top 而不是 Left-Top,从而在屏幕上的指定位置顺利打印出阿拉伯文本,而无需明确计算位置.

Therefore, you can easily move the origin of the graphics object to be Right-Top, instead of Left-Top, to print out the Arabic text in the designated location on the screen smoothly, without having to calculate locations explicit.

虽然将 (X,Y) 坐标设置为 (0,0) 时确实如此,但如果我想增加 X 坐标以在纸张的特定区域打印,X 坐标将增加到纸张的右侧在从右到左打印时,不会像它应该的那样向左;这意味着在纸外打印.看这个演示:

While this is true when setting (X,Y) coordination to (0,0) but if I want to increase X coordination to print at specific area on the paper, the X coordination will increase to the right side of the paper not to the left as it supposed to when printing in Right-to-left; which means print outside of the paper. See this demo:

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

如何将图形对象的原点移动到 Right-Top 而不是 Left-Top,当增加 X 坐标时,它会将打印点向左而不是向右移动.

How to move the origin of the graphics object to be Right-Top instead of Left-Top and when increase X coordination it advance the printing point to the left not to the right.

PS:我现在正在做的是将 X 坐标设置为负数以强制它向左移动.

PS: What I am doing now is setting X coordination to negative to force it move to left.

推荐答案

使用 StringFormatFlags.DirectionRightToLeft,像这样:

Use StringFormatFlags.DirectionRightToLeft, like this:

StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
e.Graphics.DrawString("سلام",
                this.Font,
                new SolidBrush(Color.Red),
                r1,
                format);

这篇关于在 C# 中从右到左打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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