Bartender软件
Visual Studio 2012
电脑装 BarTender软件,可到官网下载试用版本
设置程序界面
开始做个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; } } }}
打开BarTender进行设计模板,把文本对象与条形码对象拖入设计区域,,同时对对象进行命名,这个很重要,名字将影响程序调用使用的。如本程序中,模板名品名是name,条形码名是code,模板保存名为test.btw,并放在程序运行的目录下。
模板对象的名称与程序代码的中相应赋值字段名要一样