【发布时间】: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 中很好地涵盖了。