0

i'm working on window form application and i use print preview dialogue for the printing.it works that when i click on print button then print preview dialogue opens and then i have to click on print option in print preview dialogue and printer prints correctly.but my requirement is that when i click on print button then directly printer prints the document without going in print preview dialogue..i search many stack overflow question and from other sites but not get the required point,help available in java script or such other language which i not required. the code i tried is given below:

 Private Sub print_Button_Click(sender As Object, e As EventArgs) Handles print_preview_Button.Click
    PrintPreviewDialog1.Document = PrintDocument1
    PrintPreviewDialog1.ShowDialog()
End Sub

and "PrintDocument1_PrintPage" event code is

 Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
   'printing code is here... working correctly
 End Sub

where changing i should do that i get the required result....??

Ubaid
  • 77
  • 10

1 Answers1

1

Instead of using the PrintDialog class, make use ofPrintDocument class. Make sure to pass your printer's name properly.

Imports System.Drawing.Printing

....

Dim pd as New PrintDocument()
pd.PrinterSettings.PrinterName = "my printer"

In case you want to get the name of all connected printers, try :

For each s as String in PrinterSettings.InstalledPrinters

  Dim printerName as string = s

Next

Original answer reference

Software Dev
  • 5,368
  • 5
  • 22
  • 45