Cannot Alter PrintDialog Settings Programatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to alter the the printDialog properties programatically and
appear to be unable to. In the code below, I am changing the default paper
size to Legal. However, it always changes back to letter. If I change the
paper size in the dialog, it works as expected. I also tried to change the
paper size in the document.QueryPageSettings event with the same results.

If someone has a suggestion as to what I may be missing, I would appreciate
it!

Thanks,
Craig Adams
Vivus Software, Inc.

Dim legal As System.drawing.Printing.PaperSize = New
System.Drawing.Printing.PaperSize("Legal", 850, 1400)

' Allow the user to choose the printer and settings.
_printDialog = New PrintDialog
_printDialog.Document = _receiptDocument
With _printDialog
.AllowSomePages = True
'.AllowSelection = True
.PrinterSettings.DefaultPageSettings.PaperSize = legal
.Document = _receiptDocument
.Document.DefaultPageSettings.PaperSize = legal
.Document.PrinterSettings.DefaultPageSettings.PaperSize = legal
End With
Dim Result As DialogResult = _printDialog.ShowDialog()

If Result = DialogResult.OK Then
_printMode = False
_receiptDocument.PrinterSettings.PrinterName =
_printDialog.PrinterSettings.PrinterName
_receiptDocument.Print()
End If
 
If I remember correctly DefaultPageSettings is read-only, so you should set
PrintDialog.PageSettings to a new instance, and work with it.

I can't verify now but if this doesn't solve your problem let me know and
I'll look into it.

Gabriele
 
Thanks for responding Gabriele but I have tried setting
printDialog.PageSettings. When I do so, and check the property, it is set to
legal but still prints out in letter.

If you have other suggestions, I would appreciate them.
Thanks,

Craig Adams
PrintDialog .PrinterSettings.DefaultPageSettings.PaperSize = legal
 
Try with this:

Dim printDialog As New PrintDialog
Dim pageSetupDialog As New PageSetupDialog
Dim printDocument As New PrintDocument
Dim paperSize As PaperSize

pageSetupDialog.PageSettings = New Printing.PageSettings
pageSetupDialog.PrinterSettings = New Printing.PrinterSettings

For Each paperSize In pageSetupDialog.PrinterSettings.PaperSizes
If paperSize.PaperName = "Legal" Then Exit For
Next
pageSetupDialog.PageSettings.PaperSize = paperSize

With printDocument
.DefaultPageSettings = pageSetupDialog.PageSettings
.PrinterSettings = pageSetupDialog.PrinterSettings
End With

printDialog.Document = printDocument
If printDialog.ShowDialog() = DialogResult.OK Then
printDocument.Print()
End If
 
Gabriele,
You are the man. That worked perfectly!

Thanks so much for taking time to answer my post. I do appreciate it.

Craig Adams
Vivus Software, Inc.
 
Back
Top