2つの異なるジョブに2つの異なるプリンターを指定できるようにしたいと思います。これらの印刷を処理するために次のクラスを使用していますが、何をするかに関係なく、デフォルトのプリンターは常に印刷先のプリンターです。
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
DrawStringを呼び出す直前にPrinterSettings属性を調べると、PrinterName属性は指定したプリンターに正しく設定されていますが、それでもジョブを開始するデフォルトのプリンターです。私は明らかな何かを見逃していると確信していますが、誰かがそれが何であるかを指摘できれば確かにありがたいです。:)
ありがとう