资源简介
C#直接调用USB接口斑马打印机,使打印速度更快,更方便。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Drawing.Printing;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender EventArgs e)
{
//USB打印支持属于Win32_USBHub类
SelectQuery selectQuery = new SelectQuery(“Win32_USBHub“);
ManagementobjectSearcher searcher = new ManagementobjectSearcher(selectQuery);
foreach (Managementobject disk in searcher.Get())
{
string PNPDeviceID = disk[“PNPDeviceID“] as String;
BeginPrint(this.txtNum.Text.Trim() PNPDeviceID);
}
MessageBox.Show(“OK“);
}
public class Printer
{
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
private struct OVERLAPPED { int Internal; int InternalHigh; int Offset; int OffSetHigh; int hEvent; }
[System.Runtime.InteropServices.DllImport(“kernel32.dll“)]
private static extern int CreateFile(string lpFileName uint dwDesiredAccess int dwShareMode int lpSecurityAttributes int dwCreationDisposition int dwFlagsAndAttributes int hTemplateFile);
[System.Runtime.InteropServices.DllImport(“kernel32.dll“)]
private static extern bool WriteFile(int hFile byte[] lpBuffer int nNumberOfBytesToWrite out int lpNumberOfBytesWritten out OVERLAPPED lpOverlapped);
[System.Runtime.InteropServices.DllImport(“kernel32.dll“)]
private static extern bool CloseHandle(int hobject);
private int iHandle;
public bool Open(string PNPDeviceID)
{
//{A5DCBF10-6530-11D2-901F-00C04FB951ED}是USB设备类的classID
iHandle = CreateFile(“\\\\.\\“ + PNPDeviceID.Replace(‘\\‘ ‘#‘) + “#{A5DCBF10-6530-11D2-901F-00C04FB951ED}“
(uint)FileAccess.ReadWrite 0 0 (int)FileMode.Open 0 0);
if (iHandle != -1)
{
return true;
}
else
{
return false;
}
}
public bool Write(string Mystring)
{
if (iHandle != -1)
{
int i; OVERLAPPED x;
byte[] mybyte = System.Text.Encoding.Default.GetBytes(Mystring);
return WriteFile(iHandle mybyte mybyte.Length out i out x);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10752 2013-08-20 15:53 WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe
文件 28160 2013-08-20 15:53 WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb
文件 11600 2013-08-20 15:55 WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe
文件 490 2010-03-17 22:39 WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.manifest
文件 3549 2013-08-20 16:59 WindowsFormsApplication2\Form1.cs
文件 2554 2013-08-20 15:53 WindowsFormsApplication2\Form1.Designer.cs
文件 5817 2013-08-20 15:53 WindowsFormsApplication2\Form1.resx
文件 4501 2013-08-19 09:22 WindowsFormsApplication2\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6436 2013-08-20 15:53 WindowsFormsApplication2\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 264 2013-08-20 15:53 WindowsFormsApplication2\obj\x86\Debug\GenerateResource.read.1.tlog
文件 694 2013-08-20 15:53 WindowsFormsApplication2\obj\x86\Debug\GenerateResource.write.1.tlog
文件 835 2013-08-20 15:55 WindowsFormsApplication2\obj\x86\Debug\WindowsFormsApplication2.csproj.FileListAbsolute.txt
文件 10752 2013-08-20 15:53 WindowsFormsApplication2\obj\x86\Debug\WindowsFormsApplication2.exe
文件 180 2013-08-20 15:53 WindowsFormsApplication2\obj\x86\Debug\WindowsFormsApplication2.Form1.resources
文件 28160 2013-08-20 15:53 WindowsFormsApplication2\obj\x86\Debug\WindowsFormsApplication2.pdb
文件 180 2013-08-20 13:21 WindowsFormsApplication2\obj\x86\Debug\WindowsFormsApplication2.Properties.Resources.resources
文件 505 2013-08-16 10:16 WindowsFormsApplication2\Program.cs
文件 1398 2013-08-16 10:16 WindowsFormsApplication2\Properties\AssemblyInfo.cs
文件 2898 2013-08-16 10:16 WindowsFormsApplication2\Properties\Resources.Designer.cs
文件 5612 2013-08-16 10:16 WindowsFormsApplication2\Properties\Resources.resx
文件 1109 2013-08-16 10:16 WindowsFormsApplication2\Properties\Settings.Designer.cs
文件 249 2013-08-16 10:16 WindowsFormsApplication2\Properties\Settings.settings
文件 3754 2013-08-19 09:53 WindowsFormsApplication2\WindowsFormsApplication2.csproj
文件 889 2013-08-16 10:16 WindowsFormsApplication2\WindowsFormsApplication2.sln
I.A..H. 8192 2016-01-04 09:46 WindowsFormsApplication2\WindowsFormsApplication2.suo
目录 0 2013-08-16 10:16 WindowsFormsApplication2\obj\x86\Debug\TempPE
目录 0 2013-08-20 15:53 WindowsFormsApplication2\obj\x86\Debug
目录 0 2013-08-20 13:21 WindowsFormsApplication2\bin\Debug
目录 0 2013-08-16 10:16 WindowsFormsApplication2\obj\x86
目录 0 2013-08-16 10:16 WindowsFormsApplication2\bin
............此处省略6个文件信息
相关资源
- Winform可视化打印模板设计工具含源码
- C# 操作并口
- C#实现简单的Web打印控件
- C#打印条码源码
- C# 斑马标签打印 (WEBamp;WINFORM)
- 打印机监控(C#源码)
- 打印机ESC指令
- 支票管理系统源码(附数据库)
- Zebar打印机
- C# 套打Demo
- C# 调用摄像头拍照(基于AForge)
- panel内容打印(图片打印)
- C# 调用BarTender打印条码DEMO
- 大型比赛竞赛抽签系统 可打印 c# vs
- C# 斑马标签打印 WEBWINFORM
- Winform可视化打印模板设计
- C#利用Zxing.NET生成条形码和二维码并实
- C# 斑马打印机USB接口ZPL条码打印
- C#调用USB接口斑马打印机
- .net批量打印word源码C#_VS2012
- 网页js与本地C#程序 websocket通讯实现打
- 带条码打印的固定资产管理系统源码
- 热敏打印机C#二次开发包DLL
- C# 实现的3D打印
- C#调用Godex(科诚)打印机打印1,2维
- ZPL 打印条码、二维码及小票中文/汉字
- C#窗体三种方法生成二维码并打印的小
- c#快递单打印精灵
- u5-TW-C#打印操作--使用GDI绘图打印学生
- z1_C#打印操作--使用GDI绘图打印学生信
评论
共有 条评论