首页 > 解决方案 > 以从右到左的布局打印文档

问题描述

我写了这段代码:

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

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

谁能帮我?谢谢。

标签: c#.netvisual-studio

解决方案


实际上我这样做了,它的工作很棒:

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

推荐阅读