多语言展示
当前在线:1237今日阅读:84今日分享:32

C#调用Bartender打印标签

企业在生产,仓储,QC等运作环节会用到标签,Bartender是最优秀的条码打印软件,在企业里使用非常普遍,在企业应用开发的时候就避免不了需要调用Bartender。
工具/原料
1

Bartender软件

2

Visual Studio 2012

方法/步骤
1

电脑装 BarTender软件,可到官网下载试用版本

3

设置程序界面

4

开始做个DEMO打印,VS2012代码如下using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using Seagull.BarTender.Print;//这里不能少namespace WindowsFormsApplication4{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            try             {                 Engine btEngine = new Engine();                 btEngine.Start();                 string lj = AppDomain.CurrentDomain.BaseDirectory + 'test.btw';  //test.btw是BT的模板                LabelFormatDocument btFormat = btEngine.Documents.Open(lj);                 //对BTW模版相应字段进行赋值                 btFormat.SubStrings['name'].Value = spname.Text;                 btFormat.SubStrings['code'].Value = spcode.Text;                 //指定打印机名                 btFormat.PrintSetup.PrinterName = 'TSC2018';                 //改变标签打印数份连载                 btFormat.PrintSetup.NumberOfSerializedLabels = 1;                 //打印份数                                   btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;                Messages messages;                 int waitout = 10000; // 10秒 超时                 Result nResult1 = btFormat.Print('标签打印软件', waitout, out messages);                 btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.PerSession;                 //不保存对打开模板的修改                 btFormat.Close(SaveOptions.DoNotSaveChanges);                 //结束打印引擎                                  btEngine.Stop();             }             catch (Exception ex)             {                 MessageBox.Show('错误信息: ' + ex.Message);                 return;             }                 }    }}

5

打开BarTender进行设计模板,把文本对象与条形码对象拖入设计区域,,同时对对象进行命名,这个很重要,名字将影响程序调用使用的。如本程序中,模板名品名是name,条形码名是code,模板保存名为test.btw,并放在程序运行的目录下。

注意事项

模板对象的名称与程序代码的中相应赋值字段名要一样

推荐信息