打印小票,使用的是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客户端打印 ...
随机推荐
- shell脚本学习- 传递参数
跟着RUNOOB网站的教程学习的笔记 我们可以在执行shell脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n代表一个数字,1为执行脚本的第一参数,2为执行脚本的第二个参数,以此类推... 实 ...
- JavaScript基础视频教程总结(011-020章)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 让photoshop cc 支持 webp格式
下载WebP.8bi文件,看PS cc 是32位还是64位,找到对应的文件. brushes8.com-2017-11-03_08-29-21_654098.7z 把 WebP.8bi 复制到pho ...
- Alpha冲刺 (2/10)
Part.1 开篇 队名:彳艮彳亍团队 组长博客:戳我进入 作业博客:班级博客本次作业的链接 Part.2 成员汇报 组员1(组长)柯奇豪 过去两天完成了哪些任务 学习并配置了ssm框架(用于前后端交 ...
- jupyter Notebook环境搭建
1.什么是jupyter notebook jupyter notebook是一种 Web 应用,能让用户将说明文本.数学方程.代码和可视化内容全部组合到一个易于共享的文档中.它可以直接在代码旁写出叙 ...
- dubbo实现示例
创建MAVEN项目 项目结构: 在项目pom.xml中添加依赖 <dependency> <groupId>org.apache.zookeeper</groupId&g ...
- k8s docker集群搭建
一.Kubernetes系列之介绍篇 •Kubernetes介绍 1.背景介绍 云计算飞速发展 - IaaS - PaaS - SaaS Docker技术突飞猛进 - 一次构建,到处运行 - 容器 ...
- [Project] MiniSearch文本检索简介
1. 预处理过程 预处理主要用来事先生成程序在运行过程中可能用到的数据,以便加速处理时间. 预处理的过程主要生成程序所需的三个文件:网页库文件,网页位置信息文件和倒排索引文件. 网页库文件 其中网页库 ...
- 背水一战 Windows 10 (63) - 控件(WebView): 基础知识, 加载 html, http, https, ms-appx-web:///, embedded resource, ms-appdata:///, ms-local-stream://
[源码下载] 背水一战 Windows 10 (63) - 控件(WebView): 基础知识, 加载 html, http, https, ms-appx-web:///, embedded res ...
- Zhu-Takaoka Two-dimensional Pattern Matching
Two dimensional pattern matching. Details may be added later.... Corresponding more work can be foun ...