C#中要用针式打印机预览打印票据,该怎么实现啊,急求 谢谢大家的关注 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 需要使用printdocument对象 来实现 一个print事件... 和windows下的其他打印没有区别。如果不要驱动的话,可以使用直接写端口的方法。 把我做的给你参考下。。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Drawing.Printing;namespace Zsh.print{ public partial class frmBadHzd : Form { public frmBadHzd() { InitializeComponent(); } private void frmBadHzd_Paint(object sender, PaintEventArgs e) { Font font; string str; float xPos; //x点坐标 float yPos; //y点的坐标 float topMargin = 0; float leftMargin = 0; font = new Font("宋体", 12); str = "欢迎光临"; xPos = leftMargin + 15; yPos = topMargin; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 25; yPos = yPos + font.GetHeight(e.Graphics) + 3; font = new Font("黑体", 18); str = "客 户 回 执 单"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 3; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = " 凭单号"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = "业务类型"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = " 卡号"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 10; font = new Font("宋体", 11); str = " 原余额"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = " 现余额"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 50; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 14); str = "客户签名"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 130; yPos = yPos + font.GetHeight(e.Graphics) - 5; font = new Font("宋体", 12); str = "-----------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics); font = new Font("宋体", 10); str = "受理单位名称"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 10); str = " 操作员名称"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 10; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 10); str = " 日期"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("华文行楷", 12); str = "此凭单为购物凭证,请妥善保管!"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); } 接上 private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { Font font; string str; float xPos; //x点坐标 float yPos; //y点的坐标 float topMargin = 0; float leftMargin = 0; font = new Font("宋体", 12); str = "欢迎光临"; xPos = leftMargin + 15; yPos = topMargin; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 25; yPos = yPos + font.GetHeight(e.Graphics) + 3; font = new Font("黑体", 18); str = "客 户 回 执 单"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 3; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = " 凭单号"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = "业务类型"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = " 卡号"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 10; font = new Font("宋体", 11); str = " 原余额"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 11); str = " 现余额"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 50; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 14); str = "客户签名"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 130; yPos = yPos + font.GetHeight(e.Graphics) - 5; font = new Font("宋体", 12); str = "-----------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics); font = new Font("宋体", 10); str = "受理单位名称"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 10); str = " 操作员名称"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 10; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("宋体", 10); str = " 日期"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("黑体", 12); str = "---------------------------------"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin; yPos = yPos + font.GetHeight(e.Graphics) + 5; font = new Font("华文行楷", 12); str = "此凭单为购物凭证,请妥善保管!"; e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); } /// <summary> /// 打印票据信息 /// </summary> /// <param name="?">打印机名称</param> /// <param name="sho_printNum">打印数量</param> public void print(string str_Printer, short sho_printNum) { try { PrintDocument pd = new PrintDocument(); pd.PrinterSettings.PrinterName = str_Printer; pd.PrinterSettings.Copies = sho_printNum; pd.PrintController = new StandardPrintController(); pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); if (pd.PrinterSettings.IsValid) { pd.Print(); } else { MessageBox.Show("打印机连接错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception e) { MessageBox.Show(e.Message); } } }} frmBadHzd_Paint,和printDocument1_PrintPage,效果貌似一样的,print 是往纸上打印前两个所绘制的图形,是不是啊 如何让我的程序在安装之后直接关联指定格式的文件,并为该类文件指定一个图标 一个从未遇到过的问题! TcpListener.Start()的异常问题 利用Times定时发送邮件 类的访问? 页面用户控件共用sqlconnection的问题 关于分页的问题,十万火急。。。。。 C#中如何实现给现有程序加windows标准标题栏? NUnit不能测试静态变量吗? 帮我看看此段代码怎优化(有关数据库操作) C#查看本机网络配置信息 请教,怎么让电脑斗地主的水平提高,标题长长长!!!!!!!!!
如果不要驱动的话,可以使用直接写端口的方法。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;namespace Zsh.print
{
public partial class frmBadHzd : Form
{
public frmBadHzd()
{
InitializeComponent();
} private void frmBadHzd_Paint(object sender, PaintEventArgs e)
{
Font font;
string str;
float xPos; //x点坐标
float yPos; //y点的坐标
float topMargin = 0;
float leftMargin = 0; font = new Font("宋体", 12);
str = "欢迎光临";
xPos = leftMargin + 15;
yPos = topMargin;
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 25;
yPos = yPos + font.GetHeight(e.Graphics) + 3;
font = new Font("黑体", 18);
str = "客 户 回 执 单";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 3;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = " 凭单号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = "业务类型";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = " 卡号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 10;
font = new Font("宋体", 11);
str = " 原余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = " 现余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 50;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 14);
str = "客户签名";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 130;
yPos = yPos + font.GetHeight(e.Graphics) - 5;
font = new Font("宋体", 12);
str = "-----------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics);
font = new Font("宋体", 10);
str = "受理单位名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 10);
str = " 操作员名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 10;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 10);
str = " 日期";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("华文行楷", 12);
str = "此凭单为购物凭证,请妥善保管!";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());
}
{
Font font;
string str;
float xPos; //x点坐标
float yPos; //y点的坐标
float topMargin = 0;
float leftMargin = 0; font = new Font("宋体", 12);
str = "欢迎光临";
xPos = leftMargin + 15;
yPos = topMargin;
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 25;
yPos = yPos + font.GetHeight(e.Graphics) + 3;
font = new Font("黑体", 18);
str = "客 户 回 执 单";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 3;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = " 凭单号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = "业务类型";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = " 卡号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 10;
font = new Font("宋体", 11);
str = " 原余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 11);
str = " 现余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 50;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 14);
str = "客户签名";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 130;
yPos = yPos + font.GetHeight(e.Graphics) - 5;
font = new Font("宋体", 12);
str = "-----------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics);
font = new Font("宋体", 10);
str = "受理单位名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 10);
str = " 操作员名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + 10;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("宋体", 10);
str = " 日期";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("黑体", 12);
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + 5;
font = new Font("华文行楷", 12);
str = "此凭单为购物凭证,请妥善保管!";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());
} /// <summary>
/// 打印票据信息
/// </summary>
/// <param name="?">打印机名称</param>
/// <param name="sho_printNum">打印数量</param>
public void print(string str_Printer, short sho_printNum)
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = str_Printer;
pd.PrinterSettings.Copies = sho_printNum;
pd.PrintController = new StandardPrintController();
pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
if (pd.PrinterSettings.IsValid)
{
pd.Print();
}
else
{
MessageBox.Show("打印机连接错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}
print 是往纸上打印前两个所绘制的图形,是不是啊