我正在使用窗口表单应用程序,我使用打印预览对话框进行打印。它的工作原理是,当我单击打印按钮时,将打开打印预览对话框,然后我必须在打印预览对话框和打印机中单击打印选项可以正确打印。但是我的要求是,当我单击“打印”按钮时,打印机直接打印文档,而无需进入打印预览对话框。或其他我不需要的语言。我尝试的代码如下:
Private Sub print_Button_Click(sender As Object, e As EventArgs) Handles print_preview_Button.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
和“ PrintDocument1_PrintPage”事件代码为
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'printing code is here... working correctly
End Sub
我应该在哪里进行更改,以获得所需的结果。...??
答案 0 :(得分:0)
使用PrintDialog
类代替使用PrintDocument
类。确保正确输入打印机名称。
Imports System.Drawing.Printing
....
PrintDocument pd = new PrintDocument()
pd.PrinterSettings.PrinterName = "my printer"
如果要获取所有已连接打印机的名称,请尝试:
For each s as String in PrinterSettings.InstalledPrinters
Dim printerName as string = s
Next