PrinterSettings.IsDefaultPrinter PrinterSettings.IsDefaultPrinter PrinterSettings.IsDefaultPrinter PrinterSettings.IsDefaultPrinter Property

Definición

Obtiene un valor que indica si la propiedad PrinterName designa la impresora predeterminada, excepto cuando el usuario establece explícitamente la propiedad PrinterName.Gets a value indicating whether the PrinterName property designates the default printer, except when the user explicitly sets PrinterName.

public:
 property bool IsDefaultPrinter { bool get(); };
public bool IsDefaultPrinter { get; }
member this.IsDefaultPrinter : bool
Public ReadOnly Property IsDefaultPrinter As Boolean

Valor de propiedad

truesi PrinterName designa a la impresora predeterminada; en caso contrario, false.true if PrinterName designates the default printer; otherwise, false.

Ejemplos

En el ejemplo siguiente se muestra cómo utilizar IsDefaultPrinter la propiedad.The following example demonstrates how to use the IsDefaultPrinter property. Para ejecutar este ejemplo, pegue el código siguiente en un formulario y llame PopulateInstalledPrintersCombo a desde el constructor del formulario Load o el método de control de eventos.To run this example, paste the following code into a form and call PopulateInstalledPrintersCombo from the form's constructor or Load event-handling method.

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

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

Comentarios

IsDefaultPrintersiempre devuelve false cuando establece explícitamente la PrinterName propiedad en un valor de cadena distinto nullde.IsDefaultPrinter always returns false when you explicitly set the PrinterName property to a string value other than null.

Se aplica a

Consulte también: