开发者

is there any code in vb.net to check printer status

The problem seen to appear again in printing job...

I have a printer(Epson TM-T88IV Receipt). Before printing, i would like to check if printer is available for printing or not (connect or not). if not, i will show the print preview form. otherwise it will print automatically

a开发者_Python百科ny solution in vb.net code

Thanks in advance

Makara


I'm not 100% sure this will work so try it first:

'usage
For Each prn As String In PrinterSettings.InstalledPrinters
    Debug.WriteLine(String.Format("Is printer {0} online? {1}", prn, CheckPrinter(prn).ToString))
Next

'function to test printer status
Private Function CheckPrinter(ByVal printerName As String) As Boolean
    Try
        Dim printDocument As PrintDocument = New PrintDocument
        printDocument.PrinterSettings.PrinterName = printerName
        Return printDocument.PrinterSettings.IsValid
    Catch ex As System.Exception
        Return False
    End Try
End Function


As you use Vb.net I guess you are on a windows machine. Use your operating systems API. Like e.g. GetPrinterStatus.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜