直接发送字符串到打印机 [英] Sending String Directly to printer

查看:543
本文介绍了直接发送字符串到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  发送文件到打印机用C#

我要直接发送一个字符串值打印机。当然是非常好,我可以发送一个数据表打印机。但首先我想知道我怎么可以把我的字符串值,没有任何提示最终用户的打印机。 我搜索了3小时上网,但发现没有任何反应。 请帮助我。 THX:)

I want to to Send a String Value directly to printer. of course it is very better that I can send a datatable to printer. but first of all I want to know how I can send my String Value without any prompting for end user to printer. I have searched for 3 hours in internet but found no response. please help me. Thx :)

推荐答案

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

you can use PrintDocument under System.Drawing.Printing namespace. Print method will print the string using your default printer

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

从<一个发现的例子href="http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/93e54c4f-fd07-4b60-9922-102439292f52/"相对=nofollow>这里

这篇关于直接发送字符串到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆