很多生产环节都需要条码打印的功能,这篇文章就介绍下如何使用C#实现条码打印的功能,希望对大家能有所帮助!

条码设计软件采用的是BarTender 10.1,在此基础上进行的二次开发。

运行成功的预览图:

源代码地址:https://github.com/ospanic/BarTender_Dev_Dome

这是一个用c#语言编写的BarTender二次开发示例程序,展示了BarTender软件的部分功能。

使用前请先安装 BarTender 10.1 或更高版本的条码设计软件。

BarTender 10.1安装方法

1.双击软件安装包,一路NEXT完成安装。

2.将下图箭头所指的那个文件复制到Bartender的安装目录,默认安装目录如下图所示:

3.双击箭头所指的那个文件,点击PATCH按钮完成安装。

注意:BarTender 为收费软件如果你需要将其用于生产,请联系软件厂家购买正版授权。

二次开发简介

二次开发须引用UnityEngine.dll 和 Seagull.BarTender.Print.dll 这两个动态链接库文件。

并且软件还要以.NETFramework 2.0 兼容方式运行,*Demo.exe.config 文件配置如下:

<?xml version="1.0"?>
<configuration><startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup>
</configuration>

二次开发核心代码如下:

using Seagull.BarTender.Print;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;namespace BarTender_Dev_Dome
{public partial class PrintForm : Form{private string _bmp_path = Application.StartupPath + @"\exp.jpg";private string _btw_path = "";string _PrinterName = "";public PrintForm(){InitializeComponent();}private void PrintForm_Load(object sender, EventArgs e){Printers printers = new Printers();foreach (Printer printer in printers){printer_comboBox.Items.Add(printer.PrinterName);}if (printers.Count > 0){// Automatically select the default printer.printer_comboBox.SelectedItem = printers.Default.PrinterName;}}private void openFilebtn_Click(object sender, EventArgs e){OpenFileDialog dialog = new OpenFileDialog();dialog.Multiselect = false;//多个文件dialog.Title = "请选择要烧录的文件";dialog.Filter = "bwt文件(*.btw)|*.btw";dialog.InitialDirectory = Application.StartupPath;if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK){_btw_path = dialog.FileName;fileNametBox.Text = dialog.SafeFileName;fileNametBox.BackColor = Color.LightGreen;pictureBox.Image = null;using (Engine btEngine = new Engine(true)){LabelFormatDocument labelFormat = btEngine.Documents.Open(_btw_path);if (labelFormat != null){Seagull.BarTender.Print.Messages m;labelFormat.ExportPrintPreviewToFile(Application.StartupPath,  @"\exp.bmp", ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, new Resolution(300,300), System.Drawing.Color.White, OverwriteOptions.Overwrite, true, true, out m);labelFormat.ExportImageToFile(_bmp_path, ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, new Resolution(300, 300), OverwriteOptions.Overwrite);Image image = Image.FromFile(_bmp_path);Bitmap NmpImage = new Bitmap(image);pictureBox.Image = NmpImage;image.Dispose();}else{MessageBox.Show("生成图片错误", "操作提示");}}}}private void printer_comboBox_SelectedIndexChanged(object sender, EventArgs e){_PrinterName = printer_comboBox.Text;}void PrintBar(bool isPreView = false){if (_btw_path.Length < 5){fileNametBox.BackColor = Color.Red;return;}using (Engine btEngine = new Engine(true)){LabelFormatDocument labelFormat = btEngine.Documents.Open(_btw_path);try{labelFormat.SubStrings.SetSubString("name", name_textBox.Text);labelFormat.SubStrings.SetSubString("age", age_textBox.Text);labelFormat.SubStrings.SetSubString("ID", id_textBox.Text);labelFormat.SubStrings.SetSubString("code", num_textBox.Text);}catch (Exception ex){MessageBox.Show("修改内容出错 " + ex.Message, "操作提示");}if (labelFormat != null){//Generate a thumbnail for it.labelFormat.ExportImageToFile(_bmp_path, ImageType.BMP, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, new Resolution(407, 407), OverwriteOptions.Overwrite);System.Drawing.Image image = System.Drawing.Image.FromFile(_bmp_path);Bitmap NmpImage = new Bitmap(image);pictureBox.Image = NmpImage;image.Dispose();}else{MessageBox.Show("生成图片错误", "操作提示");}if (isPreView) return;if (_PrinterName != ""){labelFormat.PrintSetup.PrinterName = _PrinterName;labelFormat.Print("BarPrint" + DateTime.Now, 3 * 1000);}else{MessageBox.Show("请先选择打印机", "操作提示");}}}private void print_btn_Click(object sender, EventArgs e){PrintBar();}private void preview_btn_Click(object sender, EventArgs e){PrintBar(true);}}
}

问题反馈

Github Demo地址:https://github.com/ospanic/BarTender_Dev_Dome

如果开发过程中遇到问题,可在Github上提issue,或者在博客下方留言哦。

BarTender破解版 标签打印二次开发二维码C#预览图相关推荐

  1. zxing二维码扫描预览变形的解决方案

    -----------------------------------2018.6.1更新--------------------------------------- 附上github地址: htt ...

  2. Qt海康威视二次开发,摄像头,抓图,预览,布防,录像,停止录像

    多说无意义 直接看图 下面有下载链接 这个VIP是别人帮我开的 VIP文章也不是我设置的 是万恶的资本家CSDN弄得 如果看不了 不要骂我 下面也就是几张演示图 和下载链接 我放到前面来了 环境是VS ...

  3. 循序渐进,探寻Excel二次开发.NET源码(3)-ExcelBase类

    循序渐进,探寻Excel二次开发.NET源码(3)-ExcelBase类 --Excel打开关闭打印预览 作者:长江支流 关键字:.NET.Excel.Excel打开.Excel关闭.Excel打印预 ...

  4. wincc报表日报表实例_工作系统二次开发二Python加工原膜切割日报表数据实例

    #工作系统二次开发二Python加工原膜切割日报表数据实例 #当查询一个或多个工作令后在表格展示数据前按要求对数据进行二次处理,处理要求看如下 #1.加工单号和母卷物料编号相同则把除第一行外的领料有关 ...

  5. 类似爱美刻 右糖 轻剪辑 捷映 秀展网 秀多多 来画 创视网 传影 影大师 闪剪源码 技术源头 二次开发 提供源码 逗拍 趣推 飞推 美册 搞定视频 简影 剪影 爱字幕 幸福相册 八角星

    需要源码的下面评论 介绍 类似爱美刻 右糖 轻剪辑 捷映 秀展网 秀多多 来画 创视网 传影 影大师 闪剪源码 技术源头 二次开发 提供源码. 类似 逗拍 趣推 飞推 美册 搞定视频 简影 剪影 爱字 ...

  6. python接入Vissim二次开发,源码

    python接入Vissim二次开发,源码,刚开始学习,为了写论文,一样的朋友可以一块研究代码 代码地址 DQN VISSIM4.3 tensorflow1.2.0 https://github.co ...

  7. Android实现二维码扫描功能-ZXing识别图片二维码,相册选图

    文章目录 1.演示 2.权限问题 3.实现步骤 4.工具类 5.图片Uri处理(重要更新) 1.演示 2.权限问题 部分朋友在打开相册时遇到读写权限未授权的问题,我在开发的时候没有遇到,也没有注册读写 ...

  8. 本节作业之显示不同问候语、显示密码、关闭二维码、循环精灵图背景、显示隐藏文本框内容、密码框格式提示错误、京东关闭广告、新浪下拉菜单、开关灯、换肤、表格隔行变色、表单取消全选、tab栏切换、发布删除留言

    本节作业之显示不同问候语.显示密码.关闭二维码.循环精灵图背景.显示隐藏文本框内容.密码框格式提示错误.京东关闭广告.新浪下拉菜单.开关灯.换肤.表格隔行变色.表单取消全选.tab栏切换.发布删除留言 ...

  9. 记录安卓与uni-app混合开发遇到的坑——图片预览问题

    记录安卓与uni-app混合开发遇到的坑--图片预览问题 一.场景描述 二.需求描述 三.问题描述 四.问题解决方式 五.奉上代码(组件) 一.场景描述 用uni-app开发嵌套在安卓里面使用 二.需 ...

最新文章

  1. 美国旧金山之行第一天
  2. MyBatis3: There is no getter for property named 'code' in 'class java.lang.String'
  3. VTK:几何对象之Arrow
  4. 临时表与表变量深入探究
  5. Stream filter过滤案例
  6. Spring MVC 无XML配置入门示例
  7. oracle补零 (转)
  8. 微服务升级_SpringCloud Alibaba工作笔记0004---认识spring gateway理解新一代网关
  9. vba shell java_VBA中shell函数
  10. 遵循亚马逊标准!Kindle 电子书专业制作教程
  11. 机器人系统的基本概念及外部模型参数详解
  12. 第37天学习——CSS
  13. 如何让c语言编的游戏运行,如何用C语言编写游戏一.doc
  14. 初识流媒体与流媒体技术
  15. IIS的安装、配置与测试
  16. 用Python实现Flickr照片文本数据下载入库及图片保存(第一次帮忙)
  17. 硬盘主引导记录,主分区表,分区引导记录,分区链表介绍(转)
  18. sas入门-笔记4 描述性统计分析
  19. PHP程序测试表模板,PHPUnit 手册
  20. RQNOJ252 公司聚会 题解。

热门文章

  1. 酷科技 | Amabrush电动牙刷:10秒就可以完成刷牙
  2. macOS删除自带 ABC 输入法的方法
  3. python模拟支付宝扫码登录_GitHub - Jaccorot/alipay_python: 支付宝 alipay python接口,支持担保交易,即时到帐和自动发货接口...
  4. 宏油庄冒--菜川式快餐和小吃的完美结合
  5. linux服务器,卸载tensorflow CPU 安装PGU版
  6. Coding for NEON - Part 2: Dealing With Leftovers
  7. java实验报告4继承与多态_Java继承与多态实验报告
  8. 3行代码,为QQ轻游戏加上语音互动能力
  9. mysql事务scalar_数据库连接池、事务
  10. 轻量化软件设计五大法则