Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将字符串直接发送到打印机_C#_Visual Studio 2008_.net 3.5_Printing - Fatal编程技术网

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

C# 将字符串直接发送到打印机,c#,visual-studio-2008,.net-3.5,printing,C#,Visual Studio 2008,.net 3.5,Printing,可能重复: 我想直接向打印机发送字符串值。当然,它是非常好的,我可以发送一个数据表到打印机。但首先,我想知道如何在不向最终用户提示的情况下将字符串值发送到打印机。 我在网上搜索了3个小时,但没有找到回应。 请帮帮我。Thx:)您可以使用系统.绘图.打印命名空间下的打印文档Print方法将使用默认打印机打印字符串 string s = "string to print"; PrintDocument p = new PrintDocument(); p.PrintPage += delegat

可能重复:

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

您可以使用
系统.绘图.打印
命名空间下的
打印文档
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);
}

中找到的示例不确定您在搜索什么,但下面是我在MSDN上1分钟内找到的两篇关于打印的文章。简而言之,
PrintDocument
类通过为每个打印页面引发
PrintPage
事件来包装该功能


具有讽刺意味的是,当你搜索这篇文章时,这是谷歌的第一次点击。我相信OP想要直接将文本发送到文本打印机。就像我们以前在com端口打印机上使用windows之前所做的那样。在图形上绘制的文本实际上不是发送到打印机的字符串,而是一幅图片。