C#中要用针式打印机预览打印票据,该怎么实现啊,急求

美人心计1999 2009-08-11 04:30:00
谢谢大家的关注
我的邮箱是:miaojihao126@126.com
...全文
1546 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
luo_373883269 2010-12-28
  • 打赏
  • 举报
回复
测试下,呵呵
bmwsl 2009-08-12
  • 打赏
  • 举报
回复
普通打印还是套打?
hecker728 2009-08-12
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 miaojihao 的回复:]
在哪里调用print方法
[/Quote]

你的业务中,,需要打印的地方,,,在判断打印机驱动连接正常就调用它来打印
美人心计1999 2009-08-12
  • 打赏
  • 举报
回复
还不太懂啊,郁闷
美人心计1999 2009-08-12
  • 打赏
  • 举报
回复
在哪里调用print方法
mjp1234airen4385 2009-08-12
  • 打赏
  • 举报
回复
yes.
美人心计1999 2009-08-12
  • 打赏
  • 举报
回复
frmBadHzd_Paint,和printDocument1_PrintPage,效果貌似一样的,
print 是往纸上打印前两个所绘制的图形,是不是啊
hecker728 2009-08-11
  • 打赏
  • 举报
回复
接上

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);
}
}
}
}
hecker728 2009-08-11
  • 打赏
  • 举报
回复
把我做的给你参考下。。


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

lsj_zrp 2009-08-11
  • 打赏
  • 举报
回复
用PrintDocument就行了
hecker728 2009-08-11
  • 打赏
  • 举报
回复
打印是一样的,,就是针式打印机是小票。。排版时可以画到窗体上,通过弹出窗体进行预览
(我之前就是这么做的)
mjp1234airen4385 2009-08-11
  • 打赏
  • 举报
回复
和windows下的其他打印没有区别。
如果不要驱动的话,可以使用直接写端口的方法。
  • 打赏
  • 举报
回复
打印不都是一样的吗?
pijiuhua 2009-08-11
  • 打赏
  • 举报
回复
需要使用printdocument对象 来实现 一个print事件...
风之影子 2009-08-11
  • 打赏
  • 举报
回复
和普通的打印没有区别。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧