0

I am trying to get the printer name selected by the user from the PrintDialog, however PrintDialog1.PrinterSettings.PrinterName.Equals is returning the default windows printer name and not the printer selected in the dialog, any clues?

  Dim userResp As DialogResult = PrintDialog1.ShowDialog()
  PrintDialog1.Document = PreparePrintDocument()
  If userResp = DialogResult.OK Then
      If PrintDialog1.PrinterSettings.PrinterName.Equals("Microsoft Print to PDF") Then  
          do something
      Else
          do something else
      End If

In this example after pressing "Microsoft Print to PDF" in the dialog, debug states the value is "Canon xxx" which is the windows default printer.

Is there another way to get the printer selected in the dialog? Docs state that PrinterSettings.PrinterName can GET or SET the value?

2 Answers 2

1

Simple error. Adding this line before ShowDialog() fixed it!

  PrintDialog1.PrinterSettings = print_document.PrinterSettings
Sign up to request clarification or add additional context in comments.

Comments

0

We are just comparing strings so the = operator will do.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    If PrintDialog1.ShowDialog() = DialogResult.OK Then
        'Just to check what they chose.
        Debug.Print(PrintDialog1.PrinterSettings.PrinterName)
        If PrintDialog1.PrinterSettings.PrinterName = "Microsoft Print to PDF" Then
            MessageBox.Show("Your chose PDf.")
        End If
    End If
End Sub

Actually your code also works for me.

If PrintDialog1.PrinterSettings.PrinterName.Equals("Microsoft Print to PDF") Then

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.