我想直接向打印机发送字符串值。当然,我可以将数据表发送到打印机。但首先我想知道如何在没有任何提示最终用户打印机的情况下发送我的字符串值。 我在互联网上搜索了3个小时但没有找到回应。 请帮我。谢谢:)
答案 0 :(得分:15)
您可以在PrintDocument
命名空间下使用System.Drawing.Printing
。 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
找到示例答案 1 :(得分:2)
不确定您要搜索的是什么,但这里有两篇我在MSDN上发现的关于打印的文章。简而言之,PrintDocument
类包含了为每个正在打印的页面引发PrintPage
事件的功能。
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx