【问题标题】:How to Print with Margins如何打印边距
【发布时间】:2014-11-15 23:11:04
【问题描述】:

我正在制作一个写字板程序。我正在制作此功能,您可以在其中单击此按钮,然后将其打印到您的默认打印机。我做了一些研究,发现了一些打印到我的打印机的功能代码:

private void buttonPrint_Click(object sender, EventArgs e)
    {
        string print = "" + textBody.Text;

        PrintDocument p = new PrintDocument();
        p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
        {
            e1.Graphics.DrawString(print, new Font("Times New Roman", 12), new     SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
        };
        try
        {
            p.Print();
        }
        catch (Exception ex)
        {
            throw new Exception("Exception Occured While Printing", ex);
        }
    }

这目前有效,但我想知道我是否可以用边距制作它,它现在没有。它所做的只是:

<Top of Page>
<Message>

顶部、侧面(左、右)和底部没有边距。如何修改我的代码以获得边距?

【问题讨论】:

  • 写字板使用 RichTextBox,(几乎)与工具箱中的相同。打印其内容以使文本在纸上看起来完全一样有点复杂,但在 MSDN article 中很好地涵盖了。

标签: c# printing


【解决方案1】:

PrintDocument 上,您可以在DefaultPageSettings 对象上设置Margins

Margins margins = new Margins(100,100,100,100);
p.DefaultPageSettings.Margins = margins;

【讨论】:

  • 谢谢,帮了大忙!
猜你喜欢
  • 2012-03-29
  • 1970-01-01
  • 2017-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-20
相关资源
最近更新 更多