Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 IsDefaultPrinter Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
PrinterSettings..::.IsDefaultPrinter Property

Gets a value indicating whether the PrinterName property designates the default printer, except when the user explicitly sets PrinterName.

Namespace:  System.Drawing.Printing
Assembly:  System.Drawing (in System.Drawing.dll)
Visual Basic (Declaration)
Public ReadOnly Property IsDefaultPrinter As Boolean
Visual Basic (Usage)
Dim instance As PrinterSettings
Dim value As Boolean

value = instance.IsDefaultPrinter
C#
public bool IsDefaultPrinter { get; }
Visual C++
public:
property bool IsDefaultPrinter {
    bool get ();
}
JScript
public function get IsDefaultPrinter () : boolean

Property Value

Type: System..::.Boolean
true if PrinterName designates the default printer; otherwise, false.

IsDefaultPrinter always returns false when you explicitly set the PrinterName property to a string value other than nullNothingnullptra null reference (Nothing in Visual Basic).

The following example demonstrates how to use the IsDefaultPrinter property. To run this example, paste the following code into a form and call PopulateInstalledPrintersCombo from the form's constructor or Load event-handling method.

Visual Basic
Private WithEvents comboInstalledPrinters As New ComboBox
Private WithEvents printDoc As New PrintDocument

Private Sub PopulateInstalledPrintersCombo()
    comboInstalledPrinters.Dock = DockStyle.Top
    Controls.Add(comboInstalledPrinters)

    ' Add list of installed printers found to the combo box.
    ' The pkInstalledPrinters string will be used to provide the display string.
    Dim i As Integer
    Dim pkInstalledPrinters As String

    For i = 0 To PrinterSettings.InstalledPrinters.Count - 1
        pkInstalledPrinters = PrinterSettings.InstalledPrinters.Item(i)
        comboInstalledPrinters.Items.Add(pkInstalledPrinters)
        If (printDoc.PrinterSettings.IsDefaultPrinter()) Then
            comboInstalledPrinters.Text = printDoc.PrinterSettings.PrinterName
        End If
    Next
End Sub


C#
private ComboBox comboInstalledPrinters = new ComboBox();
private PrintDocument printDoc = new PrintDocument();

private void PopulateInstalledPrintersCombo()
{
    comboInstalledPrinters.Dock = DockStyle.Top;
    Controls.Add(comboInstalledPrinters);

    // Add list of installed printers found to the combo box.
    // The pkInstalledPrinters string will be used to provide the display string.
    int i;
    string pkInstalledPrinters;

    for (i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
    {
        pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
        comboInstalledPrinters.Items.Add(pkInstalledPrinters);
        if (printDoc.PrinterSettings.IsDefaultPrinter)
        {
            comboInstalledPrinters.Text = printDoc.PrinterSettings.PrinterName;
        }
    }
}

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker