新聞中心
C#打印條碼一般是通過(guò)圖片方式或指令方式來(lái)打印,圖片形式主要有fastreport。這里我們使用LPT端口控件來(lái)實(shí)現(xiàn),而實(shí)際上絕大多數(shù)的條碼打印機(jī)廠商都有一套他們自己的打印指令語(yǔ)言,通過(guò)這種語(yǔ)言,可以不需要驅(qū)動(dòng),支持直接打印,并且操作簡(jiǎn)單,僅僅將指令送入打印機(jī)中就好。

公司主營(yíng)業(yè)務(wù):成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)公司是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)公司推出臺(tái)州免費(fèi)做網(wǎng)站回饋大家。
VS中存在Com口操作的控件,卻未有現(xiàn)成的LPT端口控件,而相對(duì)COM口來(lái)說(shuō),LPT的速度要快,所以在打印的時(shí)候客戶一般選擇LPT通訊方式,經(jīng)過(guò)網(wǎng)上的一些查閱,終于實(shí)現(xiàn)了LPT口的打印,打印機(jī)為Zebra,寫出來(lái)與大家分享。
C#打印條碼操作的實(shí)例:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- //C#打印條碼操作的實(shí)例
- namespace PrintDemo
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- tbBarCode.Focus();
- }
- //C#打印條碼操作的實(shí)例
- private void tbBarCode_KeyDown(object sender,
- KeyEventArgs e)
- {
- switch (e.KeyCode)
- {
- case Keys.Enter:
- PrintBarcode(tbBarCode.Text.Trim());
- tbBarCode.Text = "";
- tbBarCode.Focus();
- break;
- default:
- break;
- }
- }
- private void PrintBarcode(string Barcode)
- {
- Barcode = "^XA^FO48,12^BY4^BCN,152,N,N^FD>;" +
- //C#打印條碼操作的實(shí)例
- Barcode.Trim() + "^FS^FT62,220^CI0^ABN,44,28^FD" +
- Barcode.Trim() + "^FS^PQ1,0,1,Y^XZ";
- PrintDemo.POSPrinter prn = new
- PrintDemo.POSPrinter("LPT1");
- string strmsg = prn.PrintLine(Barcode);
- if (strmsg != "")
- {
- MessageBox.Show(strmsg);
- }
- }
- }
- }
C#打印條碼操作之類POSPrinter定義如下
- namespace PrintDemo
- {
- class POSPrinter
- {
- const int OPEN_EXISTING = 3;
- string prnPort = "LPT1";
- [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
- private static extern IntPtr CreateFile(string
- lpFileName,
- int dwDesiredAccess,
- int dwShareMode,
- int lpSecurityAttributes,
- int dwCreationDisposition,
- int dwFlagsAndAttributes,
- int hTemplateFile);
- public POSPrinter()
- {
- //
- // TODO: 在此處添加構(gòu)造函數(shù)邏輯
- //
- }
- public POSPrinter(string prnPort)
- {
- this.prnPort = prnPort;//打印機(jī)端口
- }
- public string PrintLine(string str)
- {
- IntPtr iHandle = CreateFile(prnPort, 0x40000000,
- 0, 0, OPEN_EXISTING, 0, 0);
- if (iHandle.ToInt32() == -1)
- {
- return "LPT1 Port Open Failed";
- }
- else
- {
- FileStream fs = new FileStream(iHandle,
- FileAccess.ReadWrite);
- StreamWriter sw = new StreamWriter(fs,
- System.Text.Encoding.Default);//C#打印條碼操作之寫數(shù)據(jù)
- sw.WriteLine(str);
- sw.Close();
- fs.Close();
- return "";
- }
- }
- }
- }
C#打印條碼操作的實(shí)例淺析就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#打印條碼操作有所了解。
文章標(biāo)題:C#打印條碼操作的實(shí)例淺析
文章源于:http://www.dlmjj.cn/article/coiejss.html


咨詢
建站咨詢
