打印小票,使用的是BarcodeLib
打印
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的更多相关文章
- 【转】C#使用ESC指令控制POS打印机打印小票
.前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的pos ...
- C#使用ESC指令控制POS打印机打印小票
1.前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的po ...
- ActiveXObject Word.Application 打印小票
javascript 时间格式 Date.prototype.format = function (format) { var o = { "M+": this.getMonth( ...
- C# 打印小票 POS
C# 打印小票 POS 最近在写一个餐饮的收银系统,以前从来没有碰过打印机这玩意.感觉有些无从下手,在前面做报表时,总想找第三方的控件来用用,结果始终不行没搞定.没研究透,催得急没办法还是的动手自己写 ...
- C# 收银机顾显(客显)及打印小票(58热敏打印机)
最近做winform收银机,设计顾显及打印小票总结. 1.顾显(串口COM1) 只涉及到总计,所以只是简单的功能. public static ClientDisplayResult Display( ...
- 按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式
按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式 之前写过一篇文章<按照已有的模板输出一(如发票)>,是关于如何给已有的模板赋值.在项目的实践过程 ...
- C# 网络打印机ESC指令打印小票
public void SendSocketMsg(String ip, int port, int times, byte[] data) { try { byte[] mData; ) { mDa ...
- android端StarIO热敏打印机打印小票
最近在做这个热敏打印机打印小票,开始的时候在网上找资料,发现国内基本没有这方面的资料,国外也很少,在此做个打印小票的记录. 这里只记录一些关键点. 使用StarIOPort.searchPrinter ...
- 关于web页面JApplet打印小票
版权所有 做这个的例子太少,我把我做的示例亮出来 一.先说说需要的版本 1.我用的浏览器只有ie: 火狐只支持52版本以下,并且是java7.java8.chrome不支持 2.applet客户端打印 ...
随机推荐
- centos7下载
http://archive.kernel.org/centos-vault/7.0.1406/isos/x86_64/
- js计算器---转
至今见过的一个还没问题的计算器,收藏在此. 转自javascript写的简单的计算器原文链接,谢分享! js部分 ar num=0,result=0,numshow="0"; va ...
- form表单保存和取出
function saveConfig() { var configName = document.title; if (!localStorage) return; var Config = {}; ...
- Day02 (黑客成长日记)
#用户登录次数为三代码 # i = 0 # while i < 3: # username = input('请输入账号:') # password = input('请输入密码:') # if ...
- Reading | 《C++ Primer Plus》(未完待续)
目录 一.概述和C++简史 1.早期语言的问题 2.面向对象编程OOP 3.泛型编程 二.入门 1.头文件 2.名称空间 3.cout输出 4.C++语句 5.函数 一.概述和C++简史 C++融合了 ...
- java相关技术问答(一)
网上一些没有标准答案的面试题,我自己做的解答总结,有任何异议可以提出来~^_^,不断更新中... Springboot除了自动配置与传统的spring还有哪些不同 传统的springweb项目需要部署 ...
- Spring boot 参数相关注解
最近使用swagger的在线文档调试接口时发现老是报参数问题,最后发现是方法中参数上的注解有问题,今天把填的坑做一下总结. 1. RequestParam 该注解有两个属性: name/value:表 ...
- docker 中ulimit设置理解
背景: 在k8s上跑es集群碰到的问题 OS版本 红旗4.5(基于centos6.8 内核) Docker:1.17.02 现象: 本次出现的问题现象:es pod启动失败,一直报max file d ...
- 为什么我们喜欢用 sigmoid 这类 S 型非线性变换?
本文整理自 @老师木 的一条图片新浪微博,从另一个角度给出为何采用 sigmoid 函数作非线性变换的解释. 为什么我们喜欢用 sigmoid 这类 S 型非线性变换?
- 使用Project进行项目管理
下面开始介绍Project的使用. 1. 从下列地址获取Project 2010的副本. 版权问题,已删除地址. 2.安装 2.1 版权页 2.2 自定义安装页 2.3 安装完毕. 3.使用该软件进 ...