PrinterSettings.IsDefaultPrinter 属性

定义

获取一个值,该值指示 PrinterName 属性是否指定默认打印机(用户显式设置 PrinterName 的情况除外)。

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

属性值

PrinterName 指定默认打印机,则为 true;否则为 false

示例

以下示例演示如何使用 IsDefaultPrinter 属性。 若要运行此示例,请将以下代码粘贴到窗体中,并从窗体的构造函数或Load事件处理方法调用 PopulateInstalledPrintersCombo

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

注解

IsDefaultPrinter当将 属性显式设置为 PrinterName 字符串值而不是 null时,始终返回 false

适用于

另请参阅