原創(chuàng)|使用教程|編輯:龔雪|2016-03-08 17:14:58.000|閱讀 791 次
概述:本次教程主要介紹了在Barcode Professional SDK for .NET中運(yùn)用PrintDocument類打印各類型條形碼圖像的方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
正如您可能知道的那樣,大多數(shù).NET框架中的打印工作是由System.Drawing.Printing 命名空間下的PrintDocument類執(zhí)行的。Print-Document類被用來設(shè)置描述打印內(nèi)容的字符串、圖像等的屬性。main函數(shù)PrintDocument類的特點(diǎn)是打印開始文檔的打印進(jìn)程。在Print方法被調(diào)用后,PrintDocument類將為每個(gè)被打印的頁(yè)碼添加一個(gè)PrintPage事件。這就是您應(yīng)該將打印邏輯添加到該事件的事件處理程序的地方。
如果您的應(yīng)用程序需要條形碼功能起作用,那么打印包含條形碼圖像的文檔也是必須的。
Barcode Professional控制一個(gè)名為DrawOnCanvas的函數(shù)方法,該函數(shù)方法可以使你在任何GDI+ Graphics對(duì)象上繪制條形碼圖像。PrintDocument's PrintPage事件展示了一個(gè)繪制頁(yè)面內(nèi)容的Graphics對(duì)象,為了打印條形碼圖像Graphics對(duì)象必須通過DrawOnCanvas方法。
這是最簡(jiǎn)單的條形碼打印方案。例如,假設(shè)您已經(jīng)為PrintDocument's PrintPage事件設(shè)置了一個(gè)事件處理程序,在下列的代碼中,文檔/頁(yè)面中處理器程序?qū)?huì)創(chuàng)建一個(gè)Barcode Professional對(duì)象并打印在指定位置生成的條形碼圖像。
Private Sub printDocumentObject_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) 'Create a Barcode Professional object Dim bcp As New BarcodeProfessional() 'Barcode settings bcp.Symbology = Symbology.Code39 bcp.Code = "123456789" '... 'Print the barcode at x=1in, y=1in using DrawOnCanvas method bcp.DrawOnCanvas(e.Graphics, New PointF(1F, 1F)) End Sub
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //Create a Barcode Professional object BarcodeProfessional bcp = new BarcodeProfessional(); //Barcode settings bcp.Symbology = Symbology.Code39; bcp.Code = "123456789"; //... //Print the barcode at x=1in, y=1in using DrawOnCanvas method bcp.DrawOnCanvas(e.Graphics, new PointF(1f, 1f)); }
DrawOnCanvas方法的一個(gè)版本使你可以通過特定的scale參數(shù)來打印縮放的條形碼圖像。例如,如果你想把條形碼圖像縮放至當(dāng)前大小的50%,那么scale參數(shù)必須指定為0.5;如果你想把條形碼圖像擴(kuò)大至當(dāng)前大小的200%,那么scale參數(shù)必須指定為2。
假設(shè)您已經(jīng)為PrintDocument's PrintPage事件設(shè)置了一個(gè)事件處理程序,在下列的代碼中,文檔/頁(yè)碼中的處理器程序?qū)?huì)創(chuàng)建一個(gè)Barcode Professional對(duì)象并打印在指定位置生成的縮放比例為50%的條形碼圖像。
Private Sub printDocumentObject_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) 'Create a Barcode Professional object Dim bcp As New BarcodeProfessional() 'Barcode settings bcp.Symbology = Symbology.Code39 bcp.Code = "123456789" '... 'Print the barcode at x=2in, y=3in and scaled at 50% using DrawOnCanvas method bcp.DrawOnCanvas(e.Graphics, New PointF(2F, 3F), 0.5F) End Sub
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //Create a Barcode Professional object BarcodeProfessional bcp = new BarcodeProfessional(); //Barcode settings bcp.Symbology = Symbology.Code39; bcp.Code = "123456789"; //... //Print the barcode at x=2in, y=3in and scaled at 50% using DrawOnCanvas method bcp.DrawOnCanvas(e.Graphics, new PointF(2f, 3f), 0.5f); }
打印條形碼的部分區(qū)域是很常見的事,例如,要打印的條形碼圖像被指定大小為1.5英寸x1英寸,DrawOnCanvas方法使你可以用barsAreaInInches參數(shù)指定目標(biāo)區(qū)域來實(shí)現(xiàn),請(qǐng)記住關(guān)于目標(biāo)區(qū)域的以下幾點(diǎn):
假設(shè)您已經(jīng)為PrintDocument's PrintPage事件設(shè)置了一個(gè)事件處理程序,在下列的代碼中,文檔/頁(yè)碼中的處理器程序?qū)?huì)創(chuàng)建一個(gè)Barcode Professional對(duì)象并打印生成的尺寸大小為2英寸x1英寸的條形碼圖像。
Private Sub printDocumentObject_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) 'Create a Barcode Professional object Dim bcp As New BarcodeProfessional() 'Barcode settings bcp.Symbology = Symbology.Code39 bcp.Code = "123456789" '... 'Print the barcode to fit an area of size 2x1in using DrawOnCanvas method bcp.DrawOnCanvas(e.Graphics, New PointF(0,0), New SizeF(2F,1F)) End Sub
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //Create a Barcode Professional object BarcodeProfessional bcp = new BarcodeProfessional(); //Barcode settings bcp.Symbology = Symbology.Code39; bcp.Code = "123456789"; //... //Print the barcode to fit an area of size 2x1in using DrawOnCanvas method bcp.DrawOnCanvas(e.Graphics, New PointF(0,0), New SizeF(2f,1f)); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn