<分区>
Possible Duplicate:
Send document to printer with C#
我想将一个字符串值直接发送到打印机。当然,我可以将数据表发送到打印机会更好。但首先我想知道如何在不提示最终用户到打印机的情况下发送我的字符串值。 我在互联网上搜索了 3 个小时,但没有找到任何回应。 请帮我。谢谢 :)
<分区>
Possible Duplicate:
Send document to printer with C#
我想将一个字符串值直接发送到打印机。当然,我可以将数据表发送到打印机会更好。但首先我想知道如何在不提示最终用户到打印机的情况下发送我的字符串值。 我在互联网上搜索了 3 个小时,但没有找到任何回应。 请帮我。谢谢 :)
最佳答案
您可以在 System.Drawing.Printing
命名空间下使用 PrintDocument
。 Print
方法将使用默认打印机打印字符串
string s = "string to print";
PrintDocument p = new PrintDocument();
p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawString(s, 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);
}
从 here 中找到示例
关于c# - 将字符串直接发送到打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7434938/