首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

VB.NET打印小票和开钱箱解决办法

2012-02-01 
VB.NET打印小票和开钱箱我知道是老问题了,可是我还是不会,在VB.NET上打印,要加什么控件呢,怎么打出小票.各

VB.NET打印小票和开钱箱
我知道是老问题了,可是我还是不会,在VB.NET上打印,要加什么控件呢,怎么打出小票.各位老大,哪位有倒子呀,能发一个吗?
sxyc24@163.com
QQ:271821283

[解决办法]
是说有没有例子吧。
打印可以用:(在VS2005中)
PageSetupDiaglog
PrintDiaglog
PrintDocument
PrintPreviewDiaglog
[解决办法]
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
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 Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim iHandle As IntPtr
iHandle = CreateFile( "LPT1 ", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
If (iHandle.ToInt32 = -1) Then
MsgBox( "没有连接打印机或者打印机端口不是LPT1 ")
Exit Sub
Else
If i = 0 Then MsgBox( "打印机连接成功! ")

Dim fs As New FileStream(iHandle, FileAccess.ReadWrite)
Dim sr As New StreamReader(fs) '读数据
Dim sw As New StreamWriter(fs, System.Text.Encoding.Default) '写数据

sw.WriteLine()


End If
sw.Close()
End If
Next
End If
End Sub



End Function
以文件方式打开端口往里面写入指令即可.
好好看说明书吧.
当然也带有DLL的.

[解决办法]
就是以文件方式打开端口。
[解决办法]
我做的方法是将指令和小票内容写到个TXT文件,调用DOS命令打印就可以了,这种不涉及到DLL之类的,只要打印机支持就可以了(小票打印机一般都支持的)
Dim FI As Integer
FI = FreeFile
If Len(Dir( "C:\Print.txt ")) > 0 Then Kill "C:\Print.txt "
Open "C:\Print.txt " For Binary As FI
Dim K As String * 5
K = Chr(27) & Chr(112) & Chr(0) & Chr(32) & Chr(160)
Put #FI, , K
Close #FI
ShellExecute Me.hwnd, "Open ", MdbPath & "MyPrn.Bat ", " ", " ", vbHide
MyPrn.Bat内容为:
@Type C:\Print.txt > Prn
[解决办法]
http://blog.csdn.net/gaobochina/archive/2007/03/26/1541895.aspx

热点排行