直接向打印机发送字符串

可能重复:
使用C#将文档发送到打印机

我想直接向打印机发送字符串值。 当然,我可以将数据表发送到打印机。 但首先我想知道如何在没有任何提示最终用户打印机的情况下发送我的字符串值。 我在互联网上搜索了3个小时但未找到任何回复。 请帮我。 谢谢 :)

您可以在System.Drawing.Printing命名空间下使用PrintDocumentPrint方法将使用您的默认打印机打印字符串

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

从这里找到例子

不知道你在搜索什么,但这里有两篇我在MSDN上发现的关于打印的文章。 简而言之, PrintDocument类包含了为每个正在打印的页面引发的PrintPage事件的function。

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx