Difference between PrintDocument.PrinterSettings.DefaultPageSettings and PrintDocument.DefaultPageSettings

Ken Smith 125 Reputation points
2024-07-22T13:55:27.91+00:00

// Tricky! Very confusing! These statements are similar:

// (1) printDoc.PrinterSettings.DefaultPageSettings.Margins.Left = 75;

// (2) printDoc.DefaultPageSettings.Margins.Left = 75;

// In pd_PrintPage, ev.MarginBounds.Left will be equal to the Margins.Left value from statement (2).

// I don't know what scenarios use statement (1).

I see how (2) behaves in my code, but I would like to know how (1) would be used. I see that DefaultPageSettings in (1) is read-only, but what is a scenario where (1) would be used?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,872 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,643 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 43,046 Reputation points Microsoft Vendor
    2024-07-22T14:35:31.0733333+00:00

    Hi @Ken Smith , Welcome to Microsoft Q&A,

    printDoc.PrinterSettings.DefaultPageSettings.Margins.Left

    • PrinterSettings refers to the settings associated with a specific printer. PrinterSettings.DefaultPageSettings contains the default page settings associated with that printer. Changing the value of PrinterSettings.DefaultPageSettings affects all documents printed using the default settings for that printer.
    • For example:
    printDoc.PrinterSettings.DefaultPageSettings.Margins.Left = 75
    

    This code changes the page margins associated with the printer's default settings.

    printDoc.DefaultPageSettings.Margins.Left

    • PrintDocument.DefaultPageSettings contains the default page settings associated with the current print document instance. These settings apply only to the current PrintDocument instance.
    • For example:
    printDoc.DefaultPageSettings.Margins.Left = 75
    

    This code will only change the page margin settings of the current print document instance.

    Usage scenarios

    Scenario for using PrinterSettings.DefaultPageSettings (statement (1)):

    • Use PrinterSettings.DefaultPageSettings when you want to change the default settings associated with a specific printer. This is usually used to use the same printer settings uniformly in multiple print operations.

    Scenario for using DefaultPageSettings (statement (2)):

    • Use DefaultPageSettings when you want to set specific page margins for the current print document instance. This is usually used for a single print operation, or when each print document instance may have different settings. Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful