资源简介
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个文件信息
相关资源
- c#获取打印机当前打印状态完整源码
- c#datagridview小票打印单据存储
- 我写的TreeGrid源代码 TreeGrid 网格树录
- C#打印--打印商品出库单(亲测可用)
- c# asp.net webform web页面打印可以控制需
- RDLC打印二维码
- C# 同时控制两台USB连接的打印机小票
- c#实现打印功能
- C# 填充Word模版并打印
- C# 调用 bartender 打印的二次开发,含说
- 如何用VS自带报表制作打印功能
- C#斑马打印机源程序
- c#生成二维码并按指定的格式打印pa
- C#调用打印机打印
- C#二维码生成及批量打印
- .net winform调用打印机使用自定义纸张
- c# Report 报表设计工具 设计布局打印
- C#热敏小票打印机打印位图
- 佳博条码打印机C#
- C# 小票打印源码
- C#把打印中的文件输出为PDF
- c#获取本机打印机列表
- DataGridView合并单元格、分页显示、页
- C#调用CodeSoft打印标签 使用斑马打印机
- C#修改打印机设置,修改其自定义纸张
- Wince下C#开发的蓝牙打印程序
- CSharp/C#调用TSC 条码打印机 dll动态库文
- .net C#通用打印程序源代码
- C#标签设计打印程序源码
- 条码打印软件源码C#实现.rar
评论
共有 条评论