共用方式為


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

適用於

另請參閱