本文主要介绍基于第三方类库BarcodeX制作条形码及打印方法
第一步:引用类库
第二步:定义一个打印的方法
///
/// 打印条形码方法
///
/// 为PrintDocument对象的PrintPage事件提供数据
/// 待生成条形码的文本
/// 条形码宽度
/// 条形码高度
/// 偏移量X:图像距打印纸左边的距离
/// 偏移量Y:图像距打印纸顶端的距离
public void PrintBarcode( PrintPageEventArgs e,string serialNum,int imageWidth,int imageHeight,int pointX,int pointY)
{
Fath.BarcodeX barcodeX = new Fath.BarcodeX();
barcodeX.Text = serialNum;
barcodeX.Symbology = Fath.bcType.Code128;
barcodeX.ShowText = true;
e.Graphics.DrawImage(barcodeX.Image(imageWidth,imageHeight),new Point(pointX, pointY));
}
第三步:定义一个PrintDocument打印对象并绑定PrintPage事件的处理函数
定义PrintDocument对象并绑定PrintPage事件的处理函数
private void PrintPageEvent(object sender,PrintPageEventArgs e)
{
PrintBarcode(e, rtid.Text.Trim(),260,80,10,20);
}
最后调用document.Print();打印