当前位置:首页 > Windows程序 > 正文

C# 调用Bartender服务并打印bartender标签

2021-05-25 Windows程序

需求:标签模板已经设计好,,设计个简单程序调用该标签模板并打印。(标签变量通过程序传递)


以下为简单写的winform打印程序

程序界面:


技术分享

技术分享


代码如下(其中一个标签类型的代码,其他省略):

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace CS_label_Print {     public partial class BOX_Label : Form     {         public BOX_Label()         {             InitializeComponent();         }                 BarTender.Application btApp;         BarTender.Format btFormat;         private void btn2_Click(object sender, EventArgs e)         {             int a = Int32.Parse(this.num2.Value.ToString());//设置打印数量的变量             if (this.TXT3.Text.Length == 0 || this.TXT4.Text.Length == 0)             {                 MessageBox.Show("未输入料号或者QTY");             }             else             {                 btFormat = btApp.Formats.Open(@"c:\BarTenderFiles\CS\CS_Package Label", false, "");                 btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;  //设置同序列打印的份数                 btFormat.PrintSetup.NumberSerializedLabels = a;  //设置需要打印的序列数                 btFormat.SetNamedSubStringValue("SN", this.TXT3.Text); //向bartender模板传递变量                 btFormat.SetNamedSubStringValue("QTY", this.TXT4.Text);                 btFormat.PrintOut(false, false); //第二个false设置打印时是否跳出打印属性                 btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签             }         }         private void BOX_Label_Load(object sender, EventArgs e)         {             btApp = new BarTender.Application();             this.num2.Value = 1;         }         private void BOX_Label_FormClosed(object sender, FormClosedEventArgs e)         {             btApp.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程         }     } }


温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70870.html