博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
打印小票,使用的是BarcodeLib
阅读量:7084 次
发布时间:2019-06-28

本文共 4564 字,大约阅读时间需要 15 分钟。

打印

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(0).SelectNodes("IP").Item(0).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(0).SelectNodes("IP").Item(0).InnerText), int.Parse(xmld.SelectNodes("ZJY").Item(0).SelectNodes("port").Item(0).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();        ///         /// 打印取号票        ///         ///         ///         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("票据",300,300);//设置纸张的大小            pa.Document = pd;            pa.ShowDialog();//预览            if (pd.PrinterSettings.IsValid)            {                //pd.Print();                MessageBox.Show("打印成功");            }            else            {                MessageBox.Show("打印机连接错误");            }        }        ///         /// 画取号票        ///         ///         ///         void DrawPage(object sender, PrintPageEventArgs e)        {            float x,y;            float leftMargin=0,topMargin=0;                        //画标题            Font font=new Font("黑体",20);            x=leftMargin+ip.TitleNameX;            y=topMargin;            e.Graphics.DrawString(ip.TitleName,new Font("黑体",20),Brushes.Black,x,y,new StringFormat ());            //画第二行 副标题            x = leftMargin + 70;            y += font.GetHeight(e.Graphics);//返回此字体的行距            font = new Font("黑体", 15);            e.Graphics.DrawString("抽血排号凭证", font, Brushes.Black, x, y, new StringFormat());            //画排队号            x = leftMargin;            y += font.GetHeight(e.Graphics)+15;            string str = "777";            e.Graphics.DrawString(str, font, Brushes.Black, x, y, new StringFormat());            //画线            Pen pen = new Pen(Color.Black);            pen.Width = 2;            e.Graphics.DrawLine(pen, 280, 65, 10, 65);            x = leftMargin + 10;            y = y + font.GetHeight(e.Graphics)+20;            font = new Font("黑体", 20);            str = "简简";            e.Graphics.DrawString(str, font, Brushes.Black, x, y, new StringFormat());            //画你所想            x = leftMargin + 115;            y = y + font.GetHeight(e.Graphics) - 25;            font = new Font("宋体", 12);            str = "女";            e.Graphics.DrawString(str, font, Brushes.Black, x, y, new StringFormat());            x = leftMargin + 110;            y = y + font.GetHeight(e.Graphics) - 5+20;            font = new Font("宋体", 12);            str = "17";            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("宋体", 1);            b.LabelFont = font;            b.Height=50;            b.Width = 131;            image=b.Encode(BarcodeLib.TYPE.CODE128,"20180720");            e.Graphics.DrawImage(image, 155, 70, 111, 65);        }                       }}

 

}

}

转载于:https://www.cnblogs.com/Giayong/p/9342343.html

你可能感兴趣的文章
多线程的互斥
查看>>
创建redis集群时出现no such fileto load -- rubygems问题的解决
查看>>
SCOM 2012系列④客户端代理安装
查看>>
构建SSH远程登录系统(笔记)
查看>>
Linux系统安装后的基础优化
查看>>
iphone开发 ---- TableView/ToolBar
查看>>
细谈软件需求分析过程:提取、抽象、升华
查看>>
影响网站关键词排名的因素
查看>>
我的友情链接
查看>>
信任、公平、梦想—新拍拍,新起点-拍拍网蒉莺春
查看>>
read和变量设定方式
查看>>
Winmail + Rsync + Nmap 实现 Winmail 邮件系统双机热备
查看>>
python读写文件
查看>>
自编应用程序输出重定向
查看>>
unix打包压缩命令详解
查看>>
我的友情链接
查看>>
神经网络在测试抽样中的应用
查看>>
我的友情链接
查看>>
aa卫生服娃fever务而非而个
查看>>
1-4常用路由协议的梳理
查看>>