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

  • SEARCH
  • Home
  • 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 7654111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:11:48+00:00 2026-05-31T12:11:48+00:00

I am trying to modify the System.Drawing.Printing.PrinterSettings object that I get from the System.Windows.Forms.PrintDialog

  • 0

I am trying to modify the System.Drawing.Printing.PrinterSettings object that I get from the System.Windows.Forms.PrintDialog after the dialog has been shown to the user. Although I am able to change property values on the PrinterSettings object, none of the changes that I make after the dialog has been shown is actually considered when printing a document.

Here is an example of what I mean:

//Show the printdialog and retreive the printersettings    
var printDialog = new PrintDialog();
if (printDialog.ShowDialog() != DialogResult.OK) 
            return;
var printerSettings = printDialog.PrinterSettings;

//Now modify the printersettings object
printerSettings.ToPage = 8;

Now use the printerSettings object for printing. I use the 3rd Party dll Aspose.Words for this, since I need to print Word, but this seems not to be the problem. It seems like that after the dialog has been shown all settings have already been commited to the Printer and changing the PrinterSettings achieves nothing. Any Ideas on how to get this to work?

EDIT: I have some workarounds for this. What I want here is to get an answer to these specific questions: Is it possible to change the PrinterSettings object after the dialog has been shown and are these changes considered in printing. If someone knows only one way of how this can work (you can decide on what API you want to use for printing, it does not matter as long as the PrinterSettings object is used), I would be very thankful.

  • 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-31T12:11:49+00:00Added an answer on May 31, 2026 at 12:11 pm

    A few things I’ve noticed with PrintDialog (which may or may not answer your question).

    First thing is that it is just a wrapper class for the windows com dialogue.

    [DllImport("comdlg32.dll", CharSet=CharSet.Auto, SetLastError=true)]
            public static extern bool PrintDlg([In, Out] NativeMethods.PRINTDLG lppd);
    

    and second, and most important with reference to you question I guess:
    The PrintDialog class has this routine which is called after closing of the PrintDlg call

    if (!UnsafeNativeMethods.PrintDlg(data))
                    return false;
    
                IntSecurity.AllPrintingAndUnmanagedCode.Assert();
                try { 
                    UpdatePrinterSettings(data.hDevMode, data.hDevNames, data.nCopies, data.Flags, settings, PageSettings); 
                }
                finally { 
                    CodeAccessPermission.RevertAssert();
                }
    

    .
    .
    .

    // VSWhidbey 93449: Due to the nature of PRINTDLGEX vs PRINTDLG, separate but similar methods 
    // are required for updating the settings from the structure utilized by the dialog.
    // Take information from print dialog and put in PrinterSettings
    private static void UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, short copies, int flags, PrinterSettings settings, PageSettings pageSettings) {
            // Mode 
            settings.SetHdevmode(hDevMode);
            settings.SetHdevnames(hDevNames); 
    
            if (pageSettings!= null)
                pageSettings.SetHdevmode(hDevMode); 
    
            //Check for Copies == 1 since we might get the Right number of Copies from hdevMode.dmCopies...
            //this is Native PrintDialogs
            if (settings.Copies == 1) 
                settings.Copies = copies;
    
            settings.PrintRange = (PrintRange) (flags & printRangeMask); 
        }
    

    There is also a rather interesting interplay here (bearing in mind you set PrinterSettings.ToPage):

    public PrinterSettings PrinterSettings {
       get { 
            if (settings == null)
            {
                settings = new PrinterSettings(); 
            }
            return settings; 
        } 
        set {
            if (value != PrinterSettings) 
            {
                settings = value;
                **printDocument = null;**
            } 
        }
    } 
    

    and then

    public PrintDocument Document {
                get { return printDocument;}
                set {
                    printDocument = value; 
                    **if (printDocument == null)
                        settings = new PrinterSettings();** 
                    else 
                        settings = printDocument.PrinterSettings;
                } 
            }
    

    Not a direct answer I know, but I think should point you in the right direction of why it is not working. Seems to me that during the dialogue’s use, it can happily nullify the settings on changes as it will be recreated on completion, but when the Dialogue is complete, changing settings actually invalidates the document print settings until it is set again. It may be possible to do this manually, or it may be loch\ked by M$ in the usual internal/private way many internals are.

    There is an option of course (not as nice I know) to just use the Win API diectly after the call – code could be hythed from the above dialgues to build your own wrapper if required.

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

Sidebar

Related Questions

I am trying to modify the amcap, an application from Windows SDK's example to
I am trying to modify a TextBox that belongs to Form2 from within a
I'm trying to modify my GreaseMonkey script from firing on window.onload to window.DOMContentLoaded, but
Hi I'm trying to modify a web page so that it loads faster. Since
I've been trying to modify the AuditTrail code so that it does not copy
I'm trying to modify SOAP body for an outbound ws client SOAP message, from
I am trying to modify a registry key that I have been told controls
Im trying to get console output from an external application in my application. When
I am trying to use the following code to get the MBR from PhysicalDrive0
I am trying to get a PHP URI routing system to work. I am

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.