What's the best way to get the default printer in .NET

前端 未结 7 1331
生来不讨喜
生来不讨喜 2020-12-07 12:58

I need to get the default printer name. I\'ll be using C# but I suspect this is more of a framework question and isn\'t language specific.

7条回答
  •  甜味超标
    2020-12-07 13:34

    • 1st create an instance of the PrintDialog object.
    • then call the print dialog object and leave the PrinterName blank. this will cause the windows object to return the defualt printer name
    • write this to a string and use it as the printer name when you call the print procedure

    Code:

    Try
    
        Dim _printDialog As New System.Windows.Forms.PrintDialog
    
        xPrinterName = _printDialog.PrinterSettings.PrinterName '= "set as Default printer"
    
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show("could not printed Label.", "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    

提交回复
热议问题