编写源代码,我这里附上全部源代码供参考。
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;
using System.IO;
using System.Runtime.InteropServices;
namespace BlueTooth
{
public partial class Form1 : Form
{
string PalletID1;
public static BarTender.Application btapp1;
public static BarTender.Format btFormat1;
public Form1()
{
InitializeComponent();
}
private void BasicSet1()
{
string str1 = System.Windows.Forms.Application.StartupPath + "\\bluet.btw";
btapp1 = new BarTender.ApplicationClass();
btFormat1 = btapp1.Formats.Open(str1, false, "");
}
private void Form1_Load(object sender, EventArgs e)
{
BasicSet1();
}
public void PrintLabel(string PalletID1)
{
btFormat1.SetNamedSubStringValue("TEST", PalletID1);
btFormat1.IdenticalCopiesOfLabel = 1;
btFormat1.PrintOut(false, false);
}
private void print(string label)
{
PalletID1 = textBox1.Text.Trim();
PrintLabel(PalletID1);
}
private void button1_Click(object sender, EventArgs e)
{
print(textBox1.Text.Trim());
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
print(textBox1.Text.Trim());
textBox1.SelectAll();
}
}
}
}