C#调用把BarTender模板
1、应用“ Seagull.BarTender.Print “命名空间,
2、代码如下:
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;
2、代码如下:
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;
//using Seagull.BarTender;
using Seagull.BarTender.Print;
//using Seagull.BarTender;
namespace BarTenderPrintTest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Bar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Bar
string dc = @"D:\liping\BartenderPrint\BarTenderPrintTest1\BarTenderPrintTest1\bin\Debug\HW_CaiHe_and_packbox.btw";
int ff = 163704004;
string aa = "00057616-";
int i = 1;
private void btn_print_Click(object sender, EventArgs e)
{
PrintLabel3();
}
#region 第一种写法
private void PrintLabel1()
{
string aa = "00057616-";
int i = 1;
private void btn_print_Click(object sender, EventArgs e)
{
PrintLabel3();
}
#region 第一种写法
private void PrintLabel1()
{
//创建一个BarTender打印引擎 ,并启用
Engine engine = new Engine(true);
//创建一个模板对象
//LabelFormatDocument format = engine.Documents.Open("c:\\test.btw");
Engine engine = new Engine(true);
//创建一个模板对象
//LabelFormatDocument format = engine.Documents.Open("c:\\test.btw");
LabelFormatDocument format = engine.Documents.Open(@"D:\liping\BartenderPrint\BarTenderPrintTest1\BarTenderPrintTest1\bin\Debug\HW_CaiHe_and_packbox.btw");
format.Print("print me label");
//format.Print("Select printer", out messages);
//format.Close(SaveOptions.SaveChanges );
format.Print();
engine.Dispose();
format.Print("print me label");
//format.Print("Select printer", out messages);
//format.Close(SaveOptions.SaveChanges );
format.Print();
engine.Dispose();
}
#endregion
#region 打印第二种方法
private void PrintLable2()
{
using (Engine engine = new Engine())
private void PrintLable2()
{
using (Engine engine = new Engine())
{
//启用一个打印引擎
engine.Start();
//启用一个打印引擎
engine.Start();
//创建一个模板对象
LabelFormatDocument format = engine.Documents.Open(@"D:\liping\BartenderPrint\BarTenderPrintTest1\BarTenderPrintTest1\bin\Debug\HW_CaiHe_and_packbox.btw");
//打印
//format.Print("print me label");
//改变标签打印数份连载
format.PrintSetup.NumberOfSerializedLabels =1;
//设定印标签打印数量
format.PrintSetup.IdenticalCopiesOfLabel = 1;
LabelFormatDocument format = engine.Documents.Open(@"D:\liping\BartenderPrint\BarTenderPrintTest1\BarTenderPrintTest1\bin\Debug\HW_CaiHe_and_packbox.btw");
//打印
//format.Print("print me label");
//改变标签打印数份连载
format.PrintSetup.NumberOfSerializedLabels =1;
//设定印标签打印数量
format.PrintSetup.IdenticalCopiesOfLabel = 1;
Result nResult = format.Print();
//指定打印机打印,不指定则使用默认打印机
format.PrintSetup.PrinterName = "Bar Code Printer T-4503E";
//指定打印机打印,不指定则使用默认打印机
format.PrintSetup.PrinterName = "Bar Code Printer T-4503E";
// Display the print result.
//Console.WriteLine("Print status = " + nResult);
MessageBox.Show("打印提示:"+nResult );
// Close the current format without saving.
//SaveOptions 有三个值 DoNotSaveChanges:不保存 ,PromptSave:提示是否保存 SaveChanges:保存
format.Close(SaveOptions.DoNotSaveChanges);
//结束打印引擎
engine.Stop();
}
}
#endregion
#region 第三种打印方法改变标签的值
private void PrintLabel3()
{
using (Engine engine = new Engine(true))
{
LabelFormatDocument btFormat = engine.Documents.Open(dc);
//MessageBox.Show(btFormat.SubStrings[0].Name);
{
using (Engine engine = new Engine(true))
{
LabelFormatDocument btFormat = engine.Documents.Open(dc);
//MessageBox.Show(btFormat.SubStrings[0].Name);
////获取标签的值
//string AddressSubstring = btFormat.SubStrings["HWbarcode1"].Value;
//MessageBox.Show(AddressSubstring);
//修改标签的值
generic是什么牌子打印机 //btFormat.SubStrings["Address"].Value = "1313 Mockingbird Lane, Anywhere, USA";
//btFormat.SubStrings["Name"].Value = "John Doe";
//btFormat.SubStrings["Quantity"].Value = "10";
int dd = ff + i;
//string AddressSubstring = btFormat.SubStrings["HWbarcode1"].Value;
//MessageBox.Show(AddressSubstring);
//修改标签的值
generic是什么牌子打印机 //btFormat.SubStrings["Address"].Value = "1313 Mockingbird Lane, Anywhere, USA";
//btFormat.SubStrings["Name"].Value = "John Doe";
//btFormat.SubStrings["Quantity"].Value = "10";
int dd = ff + i;
i++;
btFormat.SubStrings["HWbarcode1"].Value = aa+dd.ToString ();
//改变标签打印数份连载
btFormat.PrintSetup.NumberOfSerializedLabels = 1;
//设定印标签打印数量
btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
btFormat.SubStrings["HWbarcode1"].Value = aa+dd.ToString ();
//改变标签打印数份连载
btFormat.PrintSetup.NumberOfSerializedLabels = 1;
//设定印标签打印数量
btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
Result nResult = btFormat.Print();
//指定打印机打印,不指定则使用默认打印机
btFormat.PrintSetup.PrinterName = "Bar Code Printer T-4503E";
MessageBox.Show("打印提示:" + nResult);
btFormat.Close(SaveOptions.DoNotSaveChanges);
//结束打印引擎
engine.Stop();
}
}
//指定打印机打印,不指定则使用默认打印机
btFormat.PrintSetup.PrinterName = "Bar Code Printer T-4503E";
MessageBox.Show("打印提示:" + nResult);
btFormat.Close(SaveOptions.DoNotSaveChanges);
//结束打印引擎
engine.Stop();
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论