写一段NiceLabel打印标签的.net实例程序看看
时间: 2024-02-20 19:56:17 浏览: 22
好的,以下是一个使用NiceLabel打印标签的.NET实例程序:
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NiceLabel.SDK;
using NiceLabel.SDK.Label;
using NiceLabel.SDK.Printing;
namespace NiceLabelPrintExample
{
class Program
{
static void Main(string[] args)
{
// 创建NiceLabel对象
NiceLabel label = new NiceLabel();
// 打开标签模板文件
label.OpenLabelFile("C:\\mylabel.lbl");
// 获取标签模板中的字段
Field field1 = label.GetFieldByName("field1");
Field field2 = label.GetFieldByName("field2");
// 设置标签字段的值
field1.Value = "Hello";
field2.Value = "World";
// 创建打印机对象
Printer printer = new Printer();
// 获取打印机列表
List<string> printerList = printer.GetPrinterList();
// 设置打印机
printer.PrinterName = printerList[0];
// 打印标签
label.Print(printer);
// 关闭标签模板文件和打印机
label.CloseLabelFile();
printer.Dispose();
Console.WriteLine("Label printed successfully!");
Console.ReadLine();
}
}
}
```
这个程序使用NiceLabel SDK创建了一个NiceLabel对象,打开了一个标签模板文件,获取了标签模板中的字段,设置标签字段的值,创建了一个打印机对象,设置了打印机并打印了标签。最后关闭了标签模板文件和打印机。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)