I'd like to be able to specify two different printers for two different jobs. I'm using the following class to handle printing these, but regardless of what I do, the default printer is always the one that's printed to.
Public Class Receipt : Inherits Printing.PrintDocument
Private _font As Font = New Font("Courier", 8)
Private _text As String = ""
Public Property Text() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value.Trim
End Set
End Property
Public Sub New(ByVal str As String, ByVal settings As Printing.PrinterSettings)
MyBase.New()
_text = str
Me.PrinterSettings = settings
End Sub
Protected Overrides Sub OnPrintPage(ByVal e As Printing.PrintPageEventArgs)
Dim printHeight As Integer
Dim printWidth As Integer
Dim leftMargin As Integer
Dim rightMargin As Integer
With Me.DefaultPageSettings
.PaperSize = New System.Drawing.Printing.PaperSize("Custom", 300, 1200)
.Margins.Left = 25
.Margins.Right = 25
printHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
printWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
leftMargin = .Margins.Left
rightMargin = .Margins.Top
End With
Dim printArea As New RectangleF(leftMargin, rightMargin, printWidth, printHeight)
Dim format As New StringFormat(StringFormatFlags.LineLimit)
Try
e.Graphics.DrawString(_text, _font, Brushes.Black, printArea, format)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
If I inspect my PrinterSettings attribute immediately before the call to DrawString, the PrinterName attribute is still correctly set to the printer I specify, but it's still the default printer that kicks out the job. I'm sure I'm missing something obvious, but would certainly appreciate if someone could point out what it is. :)
Thanks