网络打印机,定义打印机的端口,在打印函数中调用
示例
[Visual Basic, C#] 以下示例用指定的打印机打印文档。该示例有三个假定:已经将名为 filePath 的变量设置为要打印的文件的路径;已经定义名为 pd_PrintPage 的方法(该方法处理 PrintPage 事件);已经将名为 printer 的变量设置为打印机的名称。
[Visual Basic]
Public Sub Printing()
Try
streamToPrint = New StreamReader(filePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Specify the printer to use.
pd.PrinterSettings.PrinterName = printer
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub