1、實現BarTender的打印。
①:第一步:首先要引用Interop.BarTender.dll文件
② :第二步,直接貼代碼
public partial class Form1 : Form { private BarTender.Application btApp; //Bartender 應用實例 private BarTender.Format btFormat; //Bartender 樣式 public FormFT() { InitializeComponent(); } //標簽打印 private void button_Click(object sender, EventArgs e) { btApp = new BarTender.Application(); try { btFormat = btApp.Formats.Open(@"D:\標簽.btw", false, ""); //標簽地址 } catch (Exception) { MessageBox.Show(@"未找到D:\標簽!", "提示"); return; } btFormat.PrintSetup.NumberSerializedLabels = 1; //設置打印份數//生產型號 btFormat.SetNamedSubStringValue("product_version", txt_1.Text);
btFormat.PrintOut(true, false); //第二個參數設置是否跳出打印屬性; btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出時是否保存標簽 btApp.Quit(BarTender.BtSaveOptions.btSaveChanges);//退出時同步退出bartender進程 } }
③:上面代碼要注意幾個地方
1、要把標簽放到電腦的一個地方(如上的地址:D:\標簽.btw)
2、txt_1.Text就是winfrom上面名稱為txt_1的文本框的內容.
3、product_version就是BarTender里面的文本名稱。(如果模板上面沒有這個名稱的話,會報錯)
4、就是打印模板的電腦上面一定要安裝了BarTender這個軟件(即只有一個模板是不夠的,還要安裝軟件才行),不然程序會報錯。
2、附上BarTender軟件的樣子,下載地址就不提供了,自己找。
模板的樣子
軟件的樣子