条码打印

最近的工程要求条码打印~~咱用了简单的方法,直接调用条码对象生成图像打印--

 1 using System;

 2 using System.Collections.Generic;

 3 using System.Text;

 4     /// <summary>

 5     /// 打印编码

 6     /// </summary>

 7     public sealed class PrintBarcode

 8     {

 9         BarcodeLib.Barcode _Barcode;

10         public PrintBarcode()

11         {

12 

13             _Barcode = new BarcodeLib.Barcode();

14             _Barcode.IncludeLabel = true;

15         }

16 

17         public System.Drawing.Image Fill(string BarcodeText)

18         {

19             //---12  或者13 长度   的时候用BarcodeLib.TYPE.EAN13这个编码占小嘿嘿

20             if (BarcodeText.Length >= 12 && BarcodeText.Length <= 13)

21             {

22                 return _Barcode.Encode(BarcodeLib.TYPE.EAN13, BarcodeText, 100, 50);

23             }

24 

25 

26              //-------------------这里可以适应小于13位置

27              return _Barcode.Encode(BarcodeLib.TYPE.CODE128, BarcodeText, 100,50);

28         }

29 

30 

31 

32     }

再输出就行了哈,输出的时候用pb.Fill适配条码文本~~

BLL.PrintBarcode pb = new PrintBarcode();



        /// <summary>

        /// 打印事件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void pd_PrintPage(object sender, PrintPageEventArgs e)

        {

            //---循环打印消息开始打印

            for (int Index = PrintIndex; Index < MessingList.PrintMessing.Count; Index++)

            {

                IPrintMessing TempMessing = MessingList.PrintMessing[Index];





                //---字体大小

                int FontSize = MessingList.StyleList.Style[TempMessing.Id].FontSize;

                

                //----特殊码处理

                if (MessingList.StyleList.Style[TempMessing.Id].Type == PrintStyleType.Barcode)

                {



                    e.Graphics.DrawImage(pb.Fill(TempMessing.PrintValue), new System.Drawing.Point(TempMessing.Print_X, TempMessing.Print_Y));

                

                }

                else

                {

                    e.Graphics.DrawString(TempMessing.PrintValue, new System.Drawing.Font(new System.Drawing.FontFamily("黑体"), FontSize),

                        System.Drawing.Brushes.Black, TempMessing.Print_X, TempMessing.Print_Y);

                }

                    ////--打印后判断是否是该页结束

                if (TempMessing.isPageEnd)

                {

                    if (Index >= MessingList.PrintMessing.Count - 1)

                    {

                        //---最后一页从新设置

                        PrintIndex = 0;

                        return;

                    }

                    else

                    {

                        //---重新在执行pd_PrintPage事件

                        e.HasMorePages = true;





                        //---负值给打印打印指针,跳过当前索引

                        PrintIndex = Index + 1;



                        //---判断一页结束

                        //----跳出循环

                        return;

                    }

                }









            }

 

你可能感兴趣的:(打印)