打印

  private void Control_Click(object s,EventArgs e)
{
if (((Control)s).Name == "button1")
{
if(textBox1.Text!="")
{
XmlDocument xldoc = new XmlDocument();
xldoc.Load("D:\\Learn\\C#训练\\LikeIFace\\LikeIFace\\IPconfig.xml");
xmld.SelectNodes("ZJY").Item().SelectNodes("IP").Item().InnerText = textBox1.Text;
xmld.Save("D:\\Learn\\C#训练\\LikeIFace\\LikeIFace\\IPconfig.xml");
textBox2.Text = textBox1.Text; }
ipendpoint = new IPEndPoint(IPAddress.Parse(xmld.SelectNodes("ZJY").Item().SelectNodes("IP").Item().InnerText), int.Parse(xmld.SelectNodes("ZJY").Item().SelectNodes("port").Item().InnerText));
textBox2.Text = ipendpoint.Address.ToString();
label4.Text = ipendpoint.Port.ToString();
PrintCommand p = new PrintCommand();
p.print(); } PrintServer print = new PrintServer(); print.GetPrintQueue("Fax"); }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Printing; using Ipconfig;
using System.Windows.Forms;
using System.Data;
namespace LikeIFace
{
public class PrintCommand
{
IpconfigHelper ip = new IpconfigHelper();
/// <summary>
/// 打印取号票
/// </summary>
/// <param name="send"></param>
/// <param name="e"></param>
public void print()
{ PrintDocument pd = new PrintDocument();//new能够被打印机使用的对线
PrintPreviewDialog pa = new PrintPreviewDialog();//打印对话框
pd.PrinterSettings.PrinterName =ip.PrinterName;//打印机名称
pd.PrintController=new StandardPrintController();//获取打印机进程的控制器
pd.PrintPage += DrawPage;
pd.DefaultPageSettings.PaperSize = new PaperSize("票据",,);//设置纸张的大小
pa.Document = pd;
pa.ShowDialog();//预览
if (pd.PrinterSettings.IsValid)
{
//pd.Print();
MessageBox.Show("打印成功");
}
else
{
MessageBox.Show("打印机连接错误");
} }
/// <summary>
/// 画取号票
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void DrawPage(object sender, PrintPageEventArgs e)
{ float x,y;
float leftMargin=,topMargin=; //画标题
Font font=new Font("黑体",);
x=leftMargin+ip.TitleNameX;
y=topMargin;
e.Graphics.DrawString(ip.TitleName,new Font("黑体",),Brushes.Black,x,y,new StringFormat ());
//画第二行 副标题
x = leftMargin + ;
y += font.GetHeight(e.Graphics);//返回此字体的行距
font = new Font("黑体", );
e.Graphics.DrawString("抽血排号凭证", font, Brushes.Black, x, y, new StringFormat()); //画排队号
x = leftMargin;
y += font.GetHeight(e.Graphics)+;
string str = "";
e.Graphics.DrawString(str, font, Brushes.Black, x, y, new StringFormat()); //画线
Pen pen = new Pen(Color.Black);
pen.Width = ;
e.Graphics.DrawLine(pen, , , , ); x = leftMargin + ;
y = y + font.GetHeight(e.Graphics)+;
font = new Font("黑体", );
str = "简简";
e.Graphics.DrawString(str, font, Brushes.Black, x, y, new StringFormat()); //画你所想
x = leftMargin + ;
y = y + font.GetHeight(e.Graphics) - ;
font = new Font("宋体", );
str = "女";
e.Graphics.DrawString(str, font, Brushes.Black, x, y, new StringFormat()); x = leftMargin + ;
y = y + font.GetHeight(e.Graphics) - +;
font = new Font("宋体", );
str = "";
e.Graphics.DrawString(str, font, Brushes.Black, x, y, new StringFormat()); //画二维码
Image image;
BarcodeLib.Barcode b=new BarcodeLib.Barcode();
b.BackColor=System.Drawing.Color.White;//设置图片背景
b.ForeColor=System.Drawing.Color.Black;//设置字体颜色
b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
font = new Font("宋体", );
b.LabelFont = font;
b.Height=;
b.Width = ;
image=b.Encode(BarcodeLib.TYPE.CODE128,"");
e.Graphics.DrawImage(image, , , , ); } }
}

}
}

打印小票,使用的是BarcodeLib的更多相关文章

  1. 【转】C#使用ESC指令控制POS打印机打印小票

    .前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的pos ...

  2. C#使用ESC指令控制POS打印机打印小票

    1.前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的po ...

  3. ActiveXObject Word.Application 打印小票

    javascript 时间格式 Date.prototype.format = function (format) { var o = { "M+": this.getMonth( ...

  4. C# 打印小票 POS

    C# 打印小票 POS 最近在写一个餐饮的收银系统,以前从来没有碰过打印机这玩意.感觉有些无从下手,在前面做报表时,总想找第三方的控件来用用,结果始终不行没搞定.没研究透,催得急没办法还是的动手自己写 ...

  5. C# 收银机顾显(客显)及打印小票(58热敏打印机)

    最近做winform收银机,设计顾显及打印小票总结. 1.顾显(串口COM1) 只涉及到总计,所以只是简单的功能. public static ClientDisplayResult Display( ...

  6. 按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式

    按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式 之前写过一篇文章<按照已有的模板输出一(如发票)>,是关于如何给已有的模板赋值.在项目的实践过程 ...

  7. C# 网络打印机ESC指令打印小票

    public void SendSocketMsg(String ip, int port, int times, byte[] data) { try { byte[] mData; ) { mDa ...

  8. android端StarIO热敏打印机打印小票

    最近在做这个热敏打印机打印小票,开始的时候在网上找资料,发现国内基本没有这方面的资料,国外也很少,在此做个打印小票的记录. 这里只记录一些关键点. 使用StarIOPort.searchPrinter ...

  9. 关于web页面JApplet打印小票

    版权所有 做这个的例子太少,我把我做的示例亮出来 一.先说说需要的版本 1.我用的浏览器只有ie: 火狐只支持52版本以下,并且是java7.java8.chrome不支持 2.applet客户端打印 ...

随机推荐

  1. 位图法bitmap

    1.概念 1)所谓bitmap,就是用每一位(bit)来标记某个元素对应的value, 而key即是该元素,通常bitmap是一个int数组,用每一个int数的每一个bit来映射某个数据 2)由于采用 ...

  2. ScriptOJ-unique#89

    一般做法 const unique = (arr) => { const result = arr.reduce((acc, iter) => { if(acc.indexOf(iter) ...

  3. openxml excel封装类

    public class ExcelUntity { #region property /// <summary> /// excel文档(相当于excel程序) /// </sum ...

  4. spring+shiro+ehcache整合

    1.导入jar包(pom.xml文件) <!-- ehcache缓存框架 --> <dependency> <groupId>net.sf.ehcache</ ...

  5. SQL SERVER占用CPU过高优化

    操作系统是Windows2008R2 ,数据库是SQL2014 64位. 近阶段服务器出现过几次死机,管理员反馈机器内存使用率100%导致机器卡死.于是做了个监测服务器的软件实时记录CPU数据,几日观 ...

  6. .NET Core微服务之路:让我们对上一个Demo通讯进行修改,完成RPC通讯

    最近一段时间有些事情耽搁了更新,抱歉各位了. 上一篇我们简单的介绍了DotNetty通信框架,并简单的介绍了基于DotNetty实现了回路(Echo)通信过程. 我们来回忆一下上一个项目的整个流程: ...

  7. yesno孤立词识别kaldi脚本

    path.sh主要设定路径等 export KALDI_ROOT=`pwd`/../../.. [ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ ...

  8. 【牛客网71E】 组一组(差分约束,拆位)

    传送门 NowCoder Solution 考虑一下看到这种区间或与区间与的关系,拆一下位. 令\(s_i\)表示前缀和,则: 那么如果现在考虑到了第\(i\)为,有如下4种可能: \(opt=1\) ...

  9. ajax跨域问题小结

    跨域:跨域名的访问,是浏览器对ajax的一种限制,这样可以有效的房子跨站攻击 跨域的范畴: 域名不同  或 端口不同 或 二级域名不同 解决方案: 第一种:由于前端基础薄弱,且该方式老掉牙,不讲解: ...

  10. 移动端IM开发者必读(二):史上最全移动弱网络优化方法总结

    1.前言 本文接上篇<移动端IM开发者必读(一):通俗易懂,理解移动网络的“弱”和“慢”>,关于移动网络的主要特性,在上篇中已进行过详细地阐述,本文将针对上篇中提到的特性,结合我们的实践经 ...