您的位置首页百科知识

C#调用Bartender打印标签

C#调用Bartender打印标签

的有关信息介绍如下:

C#调用Bartender打印标签

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

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

创建WinForm项目,添加引用,浏览引用Seagull.BarTender.Print,这个DLL路径一般在C:\Program Files (x86)\Seagull\BarTender Suite\SDK\Assemblies

特别注意要在程序中写入引用using Seagull.BarTender.Print;//这里不能少

设置程序界面

开始做个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,并放在程序运行的目录下。