標籤:
其他條碼知識 請訪問:http://www.ybtiaoma.com ,本文僅供參考,請勿轉載,謝謝
using System;using System.Drawing;using System.Drawing.Printing;using System.Runtime.InteropServices;using System.Windows.Forms;/*2014-11-20 * 測試印表機 新北洋BTP-2100E Plus 西鐵城CLP-S631 * 測試結果:頁面大小,上間距,左間距都可以正常使用*/namespace PrintingExample{ public partial class frnPrinterLabel : Form { public frnPrinterLabel() { InitializeComponent(); } private PrintDocument m_printDoc = null;//列印文檔 private PrintPreviewDialog m_printPreview = null;//預覽列印UI private PrinterSettings psetting = new PrinterSettings();//執行個體列印設定對象 private float m_pageWidth = 70F;//紙張寬度 mm單位 private float m_pageHeight = 50F;//紙張高度 mm單位 private void Form1_Load(object sender, EventArgs e) { m_printDoc = new PrintDocument();//執行個體列印文檔對象 m_printPreview = new PrintPreviewDialog(); //m_printPreview.PrintPreviewControl.AutoZoom = false; m_printPreview.PrintPreviewControl.Zoom = 1; m_printPreview.Width = Screen.PrimaryScreen.Bounds.Width; m_printPreview.Height = Screen.PrimaryScreen.Bounds.Height; //自訂紙張大小 m_printDoc.DefaultPageSettings.PaperSize = new PaperSize("newPage70X40" , (int)(m_pageWidth / 25.4 * 100) , (int)(m_pageHeight / 25.4 * 100)); //自訂圖片內容整體上間距/左間距 m_printDoc.OriginAtMargins = true; m_printDoc.DefaultPageSettings.Margins.Top = (int)(2 / 25.4 * 100); m_printDoc.DefaultPageSettings.Margins.Left = (int)(2 / 25.4 * 100); //列印事件 m_printDoc.PrintPage += new PrintPageEventHandler(m_printDoc_PrintPage); } private void button1_Click(object sender, EventArgs e) { m_printDoc.Print();//列印 } private void btnView_Click_1(object sender, EventArgs e) { m_printPreview.Document = m_printDoc;//把列印文檔顯示到預覽對話方塊中 m_printPreview.ShowDialog(); } /// <summary> /// 繪製需要列印的內容 /// </summary> void m_printDoc_PrintPage(object sender, PrintPageEventArgs e) { //建立文本資訊 e.Graphics.DrawString("杭州允博條碼科技有限公司", new Font("宋體", 15), Brushes.Black, 2, 2); e.Graphics.DrawString("地址:杭州市江幹區九堡家苑三區\r\n" + "電話:0571-87298557\r\n"+ "連絡方式:15158883623" , new Font("宋體", 10), Brushes.Black, 2, 30); //建立二維碼--需要引用DLL
DotNetBarcode QRBarcode = new DotNetBarcode();//執行個體二維碼
QRBarcode.Type = DotNetBarcode.Types.QRCode;
QRBarcode.QRSetTextType = DotNetBarcode.QRTextTypes.Automatic; QRBarcode.QRWriteBar("杭州允博條碼科技有限公司", 2, 100, 2, e.Graphics); } }}
C#控制條碼印表機 紙張大小,間距,繪製內容(所有條碼印表機通用)