PC Review


Reply
Thread Tools Rate Thread

Cannot Alter PrintDialog Settings Programatically

 
 
=?Utf-8?B?Q3JhaWcgQWRhbXM=?=
Guest
Posts: n/a
 
      26th Oct 2005
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
 
Reply With Quote
 
 
 
 
Gabriele G. Ponti
Guest
Posts: n/a
 
      26th Oct 2005
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


 
Reply With Quote
 
=?Utf-8?B?Q3JhaWcgQWRhbXM=?=
Guest
Posts: n/a
 
      26th Oct 2005
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

"Gabriele G. Ponti" wrote:

> 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
>
>
>

 
Reply With Quote
 
Gabriele G. Ponti
Guest
Posts: n/a
 
      27th Oct 2005
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


 
Reply With Quote
 
=?Utf-8?B?Q3JhaWcgQWRhbXM=?=
Guest
Posts: n/a
 
      27th Oct 2005
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.

"Gabriele G. Ponti" wrote:

> 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
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WPF: PrintDialog and printer settings Julia M Microsoft C# .NET 0 18th Aug 2009 08:33 AM
PrintDialog Security Settings ajstadlin Microsoft C# .NET 0 12th Feb 2009 07:16 PM
Programatically alter width of field in datasheet view Paul Microsoft Access Form Coding 1 13th Oct 2004 01:51 PM
Cannot Alter PrintDialog Settings Programatically Lee Ottaway Microsoft Dot NET Framework 1 11th Aug 2004 07:07 AM
Re: Alter Custom Toolbars Programatically Alex Dybenko Microsoft Access VBA Modules 0 5th Aug 2003 07:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 AM.