这是与Hans 建议的方法类似的方法,但它使用表单控件。如果您仍然使用表单控件,这可能是一种更简洁的方法。
将PrintDocument
Windows 窗体工具箱中的一个放置到您的窗体中。
然后添加以下代码来处理打印页面(作为示例):
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim printerhdc As IntPtr = e.Graphics.GetHdc()
' Do whatever you need to do to get the right image
XYZ.Load file(currentpagenumber)
XYZ.Render(printerhdc.ToInt64, 25, 25, Width, Height)
CurrentPageNumber += 1
If CurrentPageNumber < TotalPageCount Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
e.Graphics.ReleaseHdc(printerhdc)
End Sub
...
'Gather all the files you need and put their names in an arraylist.
'Then issue the print command
PrintDocument1.Print
' You've just printed your files
来源:http ://www.vbforums.com/showthread.php?247493-Good-ol-Printer-hDC
(来源:http ://www.vbforums.com/showthread.php?247493-Good-ol-Printer-hDC )