PageSettings.PrinterResolution Property
Gets or sets the printer resolution for the page.

Namespace: System.Drawing.Printing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

Visual Basic (Declaration)
Public Property PrinterResolution As PrinterResolution
Visual Basic (Usage)
Dim instance As PageSettings
Dim value As PrinterResolution

value = instance.PrinterResolution

instance.PrinterResolution = value
C#
public PrinterResolution PrinterResolution { get; set; }
C++
public:
property PrinterResolution^ PrinterResolution {
    PrinterResolution^ get ();
    void set (PrinterResolution^ value);
}
J#
/** @property */
public PrinterResolution get_PrinterResolution ()

/** @property */
public void set_PrinterResolution (PrinterResolution value)
JScript
public function get PrinterResolution () : PrinterResolution

public function set PrinterResolution (value : PrinterResolution)
XAML
Not applicable.

Property Value

A PrinterResolution that specifies the printer resolution for the page. The default is the printer's default resolution.
Exceptions

Exception typeCondition

InvalidPrinterException

The printer named in the PrinterSettings.PrinterName property does not exist or there is no default printer installed.

Remarks

A PrinterResolution represents the printer resolution of through the PrinterResolution.Kind property, which contains one of the PrinterResolutionKind values.

Set the PrinterResolution property for the page to a valid PrinterResolution, available through the PrinterSettings.PrinterResolutions collection.

Example

The following code example sets three properties for the document's default page, including the printer's resolution based upon the resolution selected in the comboPrintResolution combo box, and then prints the document using the Print method. The example requires that a PrintDocument variable named printDoc exists and that the specific combo boxes exist.

Visual Basic
Private Sub MyButtonPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButtonPrint.Click

    ' Set the paper size based upon the selection in the combo box.
    If comboPaperSize.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PaperSize = _
        printDoc.PrinterSettings.PaperSizes.Item(comboPaperSize.SelectedIndex)
    End If

    ' Set the paper source based upon the selection in the combo box.
    If comboPaperSource.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PaperSource = _
        printDoc.PrinterSettings.PaperSources.Item(comboPaperSource.SelectedIndex)
    End If

    ' Set the printer resolution based upon the selection in the combo box.
    If comboPrintResolution.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PrinterResolution = _
        printDoc.PrinterSettings.PrinterResolutions.Item(comboPrintResolution.SelectedIndex)
    End If

    ' Print the document with the specified paper size and source.
    printDoc.Print()

End Sub
C#
private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
    // Set the paper size based upon the selection in the combo box.
    if (comboPaperSize.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSize = 
            printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
    }

    // Set the paper source based upon the selection in the combo box.
    if (comboPaperSource.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSource = 
            printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
    }
    
    // Set the printer resolution based upon the selection in the combo box.
    if (comboPrintResolution.SelectedIndex != -1) 
    {
        printDoc.DefaultPageSettings.PrinterResolution= 
            printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
    }

    // Print the document with the specified paper size, source, and print resolution.
    printDoc.Print();
}
C++
private:
   void MyButtonPrint_Click( Object^ sender, System::EventArgs^ e )
   {
      // Set the paper size based upon the selection in the combo box.
      if ( comboPaperSize->SelectedIndex != -1 )
      {
         printDoc->DefaultPageSettings->PaperSize = printDoc->PrinterSettings->PaperSizes[ comboPaperSize->SelectedIndex ];
      }

      // Set the paper source based upon the selection in the combo box.
      if ( comboPaperSource->SelectedIndex != -1 )
      {
         printDoc->DefaultPageSettings->PaperSource = printDoc->PrinterSettings->PaperSources[ comboPaperSource->SelectedIndex ];
      }

      // Set the printer resolution based upon the selection in the combo box.
      if ( comboPrintResolution->SelectedIndex != -1 )
      {
         printDoc->DefaultPageSettings->PrinterResolution = printDoc->PrinterSettings->PrinterResolutions[ comboPrintResolution->SelectedIndex ];
      }

      // Print the document with the specified paper size, source, and print resolution.
      printDoc->Print();
   }
J#
private void myButtonPrint_Click(Object sender, System.EventArgs e)
{
    // Set the paper size based upon the selection in the combo box.
    if (comboPaperSize.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PaperSize(printDoc.
            get_PrinterSettings().get_PaperSizes().
            get_Item(comboPaperSize.get_SelectedIndex()));
    }
    // Set the paper source based upon the selection in the combo box.
    if (comboPaperSource.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PaperSource(printDoc.
            get_PrinterSettings().get_PaperSources().
            get_Item(comboPaperSource.get_SelectedIndex()));
    }
    // Set the printer resolution based upon the selection in the combo box.
    if (comboPrintResolution.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PrinterResolution(printDoc.
            get_PrinterSettings().get_PrinterResolutions().
            get_Item(comboPrintResolution.get_SelectedIndex()));
    }
    // Print the document with the specified paper size, source,
    // and print resolution.
    printDoc.Print();
} //myButtonPrint_Click
Platforms

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
See Also

Tags :


Page view tracker