PrinterSettings.IsDefaultPrinter Property

Definition

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

C#
public bool IsDefaultPrinter { get; }

Property Value

true if PrinterName designates the default printer; otherwise, false.

Examples

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.

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

Remarks

IsDefaultPrinter always returns false when you explicitly set the PrinterName property to a string value other than null.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also