Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 306197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:26:41+00:00 2026-05-12T07:26:41+00:00

I’d like to be able to specify two different printers for two different jobs.

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:26:42+00:00Added an answer on May 12, 2026 at 7:26 am

    I just created a test app with the class code you posted and it works fine. It uses whatever printer I select. So I must conclude that wherever you are using this class you’re accidentally altering the PrintSettings object after you initialize the object but before you call Print.

    Or perhaps the printer name you specify isn’t valid and the default is used as a backup. You can check this using PrinterSettings.IsValid after setting the PrinterName property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.