【问题标题】:Print Document in Right-to-Left Layout以从右到左的布局打印文档
【发布时间】:2021-10-12 11:20:00
【问题描述】:

我写了这段代码:

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
    e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
    Font normalFont = new Font("B nazanin",25);
    StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
    e.Graphics.DrawString("سلام", normalFont, Brushes.Black, 0, 0 , format);

}

private void btnPrint_Click(object sender, EventArgs e)
{
    try
    {
        printPreviewDialog.Document = printDocument;
        pageSetupDialog.PageSettings = printDocument.DefaultPageSettings;
        pageSetupDialog.ShowDialog();
        printDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
        printPreviewDialog.ShowDialog();
    }
    catch
    {
        MessageBox.Show("error");
    }
}

它工作得很好,但问题是它从右到左打印文本,我也需要从右到左打印文档。这样它就不会显示我的文本,因为它将不在我的文档中。

谁能帮帮我?谢谢。

【问题讨论】:

  • StringFormat 对象的对齐属性在传递打印位置而不是边界时无效。您需要使用采用Rectangle + StringFormat 的重载来避免您在下面的答案中出现的情况。请参阅overloads 和那里的示例。

标签: c# .net visual-studio


【解决方案1】:

实际上我这样做了,而且效果很好:

int widthNegetive = printDocument.DefaultPageSettings.PaperSize.Width;
e.Graphics.DrawString("متن", normalFont, Brushes.Black, widthNegetive, 0, format);

【讨论】:

    猜你喜欢
    • 2017-02-21
    • 2017-07-22
    • 2021-01-26
    • 2013-10-02
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多