編寫斑馬打印機代碼
版权声明:原创作品,谢绝转载!否则将追究法律责任。 |
在頁面類下先進行聲明:
Public Class Form1
Inherits System.Windows.Forms.Form Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000 Public Const OPEN_EXISTING = 3 Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _ (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As IntPtr 在進行方法調用:
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If TextBox16.Text.Trim.Length <> 18 Then TextBox16.Clear() TextBox16.Focus() Label33.Text = "號碼長度不對,請重新輸入!" Label33.ForeColor = Color.Red Else Try Dim iHandle As IntPtr iHandle = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0) If (iHandle.ToInt32 = -1) Then
MsgBox("Can not open port") Exit Sub Else Dim fs As New FileStream(iHandle, FileAccess.ReadWrite) Dim sw As New StreamWriter(fs) sw.WriteLine("^XA")
sw.WriteLine("^LH" & X2.Text.Trim() & "," & Y2.Text.Trim() & "^FS") sw.WriteLine("^FO " & CStr(80 + CInt(X2.Text.Trim())) & "," & CStr(27 + CInt(Y2.Text.Trim())) & "^BY2,3,80^BCN,,N,N,^FD" + TextBox16.Text.Trim() + "^FS")
sw.WriteLine("^FO " & CStr(80 + CInt(X2.Text.Trim())) & "," & CStr(80 + CInt(Y2.Text.Trim())) & "^A0N,15,25^FR^FD" + TextBox16.Text.Trim() + "^FS") sw.WriteLine("^PQ1,,1,N^FS")
sw.WriteLine("^XZ") sw.Close() fs.Close() End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "Print提示") End Try End If End Sub 本文出自 “熱血王朝” 博客,谢绝转载! 本文出自 51CTO.COM技术博客 |


Jack.Li
博客统计信息
热门文章
最新评论
友情链接
