回复人: watt(瓦特)
你这个问题应该使用按行打印技术(Print line by line),而不是按页打印(print page by page),下面是代码。使用按行打印只能在支持连续纸的打印机上实现,激光的不行。
http://support.microsoft.com/support/kb/articles/Q175/0/83.asp
HOWTO: Print Line-by-Line to a Printer (Q175083)
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual Basic Learning Edition for Windows, versions 5.0 , 6.0
Microsoft Visual Basic Professional Edition for Windows, versions 5.0 , 6.0
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0 , 6.0
Microsoft Visual Basic Standard Edition, 32-bit, for Windows, version 4.0
Microsoft Visual Basic Professional Edition, 32-bit, for Windows, version 4.0
Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, version 4.0
--------------------------------------------------------------------------------
SUMMARY
Printing page-by-page is the Windows standard; however, it is sometimes desirable to print to a printer line-by-line rather than page-by-page. One advantage to printing line-by-line is that if there is a power failure while printing, the data lost is one log item, at most. The Visual Basic Printer object does not support this mode, but the Win32 API accomplishes this handily.
MORE INFORMATION
This technique will work only when printing to a local line printer, typically a dot matrix printer. Laser and Ink Jet printers are page printers and will not print in single line mode.
Create a new Visual Basic project and place a CommandButton on Form1.
Add the following code to Form1:
Option Explicit
Private Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long
Dim lhPrinter As Long
Private Sub Command1_Click()
Dim lReturn As Long
Dim lpcWritten As Long
Dim sWrittenData As String
sWrittenData = "How's that for Magic !!!!" & vbCrLf
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
End Sub
Private Sub Form_Load()
Dim lReturn As Long
Dim lDoc As Long
Dim MyDocInfo As DOCINFO
lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
If lReturn = 0 Then
MsgBox "The Printer Name you typed wasn't recognized."
Exit Sub
End If
MyDocInfo.pDocName = "AAAAAA"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim lReturn As Long
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
Make the logging printer the default and run the application. Every time you click Command1, a line should be immediately printed to your printer.
WARNING: Pressing the End button on the toolbar or selecting the Run / End menu option will not close the current print job and may block further jobs from printing to that printer. This is because the code to close the print job is in the Form_Unload event. This event is not executed when the sample is closed by the design environment. Always terminate the application by clicking the Close button, using the System menu, or entering Alt-F4.
REFERENCES
For more information about using the Win32 API to send data directly to the printer, please see the following article in the Microsoft Knowledge Base:
Q154078 : HOWTO: Send Raw Data to a Printer Using the Win32 API from VB
你这个问题应该使用按行打印技术(Print line by line),而不是按页打印(print page by page),下面是代码。使用按行打印只能在支持连续纸的打印机上实现,激光的不行。
http://support.microsoft.com/support/kb/articles/Q175/0/83.asp
HOWTO: Print Line-by-Line to a Printer (Q175083)
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual Basic Learning Edition for Windows, versions 5.0 , 6.0
Microsoft Visual Basic Professional Edition for Windows, versions 5.0 , 6.0
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0 , 6.0
Microsoft Visual Basic Standard Edition, 32-bit, for Windows, version 4.0
Microsoft Visual Basic Professional Edition, 32-bit, for Windows, version 4.0
Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, version 4.0
--------------------------------------------------------------------------------
SUMMARY
Printing page-by-page is the Windows standard; however, it is sometimes desirable to print to a printer line-by-line rather than page-by-page. One advantage to printing line-by-line is that if there is a power failure while printing, the data lost is one log item, at most. The Visual Basic Printer object does not support this mode, but the Win32 API accomplishes this handily.
MORE INFORMATION
This technique will work only when printing to a local line printer, typically a dot matrix printer. Laser and Ink Jet printers are page printers and will not print in single line mode.
Create a new Visual Basic project and place a CommandButton on Form1.
Add the following code to Form1:
Option Explicit
Private Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long
Dim lhPrinter As Long
Private Sub Command1_Click()
Dim lReturn As Long
Dim lpcWritten As Long
Dim sWrittenData As String
sWrittenData = "How's that for Magic !!!!" & vbCrLf
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
End Sub
Private Sub Form_Load()
Dim lReturn As Long
Dim lDoc As Long
Dim MyDocInfo As DOCINFO
lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
If lReturn = 0 Then
MsgBox "The Printer Name you typed wasn't recognized."
Exit Sub
End If
MyDocInfo.pDocName = "AAAAAA"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim lReturn As Long
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
Make the logging printer the default and run the application. Every time you click Command1, a line should be immediately printed to your printer.
WARNING: Pressing the End button on the toolbar or selecting the Run / End menu option will not close the current print job and may block further jobs from printing to that printer. This is because the code to close the print job is in the Form_Unload event. This event is not executed when the sample is closed by the design environment. Always terminate the application by clicking the Close button, using the System menu, or entering Alt-F4.
REFERENCES
For more information about using the Win32 API to send data directly to the printer, please see the following article in the Microsoft Knowledge Base:
Q154078 : HOWTO: Send Raw Data to a Printer Using the Win32 API from VB
解决方案 »
- 串口通信数据显示格式问题!!!
- ACCESS 中的VBA 如何连接mysql?分不多,请多包涵
- 如何得到Treeview 的Node的handle?
- 最后100分拉!!!便宜让你拣那!!!!!!!!!!!大放血!!!!!!!
- 如何得知一特定程序的关闭?
- VB+SQL 的入门级问题
- 在VB中像IE一樣的標準按鈕用的什么控件?為什麽我用的突出來了!!!
- 菜鸟问关于用VB对数据库建立问题。
- 急救!!!!急救!!!!急救!!!!急救!!!!
- #########--XML调用removechild之后,有没有一个存盘操作?
- 我最近编了一个程序,请大家来看看好吗?
- 关于VB中datareport的问题,谢谢!
每次在纸张上打印完毕后换页就可以了。
如果不是连续纸 就需要计算出每张纸的可以打印多少行 然后换行sql2000何acess2000差不多 就是细节上有些差别