注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 linux服务器被黑了
 帮助

編寫斑馬打印機代碼


2008-04-14 16:49:46
 标签:代码 打印机   [推送到技术圈]

版权声明:原创作品,谢绝转载!否则将追究法律责任。
在頁面類下先進行聲明:
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

本文出自 “熱血王朝” 博客,谢绝转载!





    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: