資源簡介
C#熱敏小票打印機打印位圖,可以打印條形碼和二維碼還有簡單的圖片

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Drawing.Printing;
using?System.IO;
using?System.Text;
using?System.Windows.Forms;
namespace?LPTPrinter
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????//調(diào)用函數(shù)
????????LptControl?lc?=?new?LptControl(“l(fā)pt1“);
????????//打開端口
????????private?void?btnOpen_Click(object?sender?EventArgs?e)
????????{
????????????if?(txtLpt.Text.Trim()?==?““)
????????????{
????????????????MessageBox.Show(“LPT端口不能為空!“);
????????????????return;
????????????}
????????????lc?=?new?LptControl(txtLpt.Text);
????????????if?(!lc.Open())
????????????{
????????????????ShowMessage(“打開LPT端口失敗!“);
????????????????return;
????????????}
????????????btnOpen.Enabled?=?false;
????????????btnClose.Enabled?=?true;
????????}
????????//在文本中顯示成功與否信息
????????private?void?ShowMessage(string?msg)
????????{
????????????txtMessage.AppendText(msg);
????????????txtMessage.AppendText(“\r\n“);
????????}
????????///?
????????///?關(guān)閉端口
????????///?
????????///?
????????///?
????????private?void?btnClose_Click(object?sender?EventArgs?e)
????????{
????????????//調(diào)用關(guān)閉方法
????????????lc.Close();
????????????//把關(guān)閉按鈕置為不可用,打開按鈕置為可用
????????????btnOpen.Enabled?=?true;
????????????btnClose.Enabled?=?false;
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????}
????????private?void?pictureBox1_Click(object?sender?EventArgs?e)
????????{
????????}
????????///?
????????///?打印圖片方法
????????///?
????????public?void?PrintOne()
????????{
????????????//獲取圖片
????????????Bitmap?bmp?=?new?Bitmap(pictureBox1.Image);
????????????//設(shè)置字符行間距為n點行
????????????byte[]?data?=?new?byte[]?{?0x1B?0x33?0x00?};
????????????
????????????lc.Write(data);
????????????data[0]?=?(byte)‘\x00‘;
????????????data[1]?=?(byte)‘\x00‘;
????????????data[2]?=?(byte)‘\x00‘;????//?Clear?to?Zero.
????????????Color?pixelColor;
????????????//ESC?*?m?nL?nH?d1…dk???選擇位圖模式
????????????//?ESC?*?m?nL?nH
????????????byte[]?escBmp?=?new?byte[]?{?0x1B?0x2A?0x00?0x00?0x00?};
????????????escBmp[2]?=?(byte)‘\x21‘;
????????????//nL?nH
????????????escBmp[3]?=?(byte)(bmp.Width?%?256);
????????????escBmp[4]?=?(byte)(bmp.Width?/?256);
????????????//循環(huán)圖片像素打印圖片
????????????//循環(huán)高
????????????for?(int?i?=?0;?i?(bmp.Height?/?24?+?1);?i++)
????????????{
????????????????//設(shè)置模式為位圖模式
????????????????lc.Write(escBmp);
????????????????//循環(huán)寬
????????????????for?(int?j?=?0;?j?????????????????{
????????????????????for?(int?k?=?0;?k?24;?k++)
????????????????????{
????????????????????????if?(((i?*?24)?+?k)?????????????????????????{
????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????I.A....???????167??2012-12-31?21:52??LPTPrinter\LPTPrinter\App.config
?????文件??????95744??2012-12-31?22:57??LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.exe
?????文件????????167??2012-12-31?21:52??LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.exe.config
?????文件??????32256??2012-12-31?22:57??LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.pdb
????I.A....?????22472??2012-12-31?22:57??LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.vshost.exe
????I.A....???????167??2012-12-31?21:52??LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.vshost.exe.config
????I.A....???????490??2012-06-02?22:34??LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.vshost.exe.manifest
????I.A....????120054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\200-200.bmp
????I.A....?????81654??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\200.bmp
????I.A....??????7759??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\230-230.jpg
????I.A....????188054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\250-250.bmp
????I.A....????127894??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\250.bmp
????I.A....?????90054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\300-150.bmp
????I.A....????153054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\300-170.bmp
????I.A....?????12054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\300-2.bmp
????I.A....????270054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\300-300.bmp
????I.A....????183654??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\300.bmp
????I.A....????172628??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\300x.bmp
????I.A....????368254??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\350-350.bmp
????I.A....????480054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\400-400.bmp
????I.A....????326454??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\400.bmp
????I.A....?????56968??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\900-900.jpg
????I.A....????193554??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\aa.bmp
????I.A....??????9654??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\bb.bmp
????I.A....?????60054??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\cc.bmp
????I.A....?????43218??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\f858ad6bb75b99382dac54fca42a35f9.bmp
????I.A....?????74588??2012-12-31?17:29??LPTPrinter\LPTPrinter\bin\Debug\picture\f858ad6bb75b99382dac54fca42a35f9.jpg
????I.A....??????5017??2012-12-31?22:57??LPTPrinter\LPTPrinter\Form1.cs
????I.A....??????7905??2012-12-31?17:29??LPTPrinter\LPTPrinter\Form1.Designer.cs
????I.A....????128807??2012-12-31?17:29??LPTPrinter\LPTPrinter\Form1.resx
............此處省略176個文件信息
評論
共有 條評論