c# - 将字符串直接发送到打印机

标签 c# visual-studio-2008 .net-3.5 printing

<分区>

Possible Duplicate:
Send document to printer with 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);
}

here 中找到示例

关于c# - 将字符串直接发送到打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7434938/

相关文章:

c# - 输入错误后继续在类之间循环

asp.net - 整数列表到逗号分隔的字符串

c# - Form.Parent 和 StartPosition.CenterParent

c# - 是否有用于匹配(语法分析)树中模式的 C# 实用程序?

c# - 现实世界应用程序中的碰撞

c++ - Visual Studio 2008 C++ 语言支持?

c++ - Visual Studio 2008 C++ 误报内存地址位置

c# - 如何获取类(class)名称

c# - 如何在不使用 HttpContext.Current 的情况下获取 ASP.NET Web 应用程序的物理位置?

c# - "Using"与 [DllImport]?