PrintDialog 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
叫用根據使用者輸入設定 PrintTicket 和 PrintQueue 的標準 Microsoft Windows 列印對話方塊,然後列印文件。
public ref class PrintDialog
public class PrintDialog
type PrintDialog = class
Public Class PrintDialog
- 繼承
-
PrintDialog
下列範例示範如何使用 Extensible Application Markup Language (XAML) 標記和程式碼,建立 實例並顯示簡單 PrintDialog 。
<Button Width="200" Click="InvokePrint">Invoke PrintDialog</Button>
...
private void InvokePrint(object sender, RoutedEventArgs e)
{
// Create the print dialog object and set options
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
// Display the dialog. This returns true if the user presses the Print button.
Nullable<Boolean> print = pDialog.ShowDialog();
if (print.Value)
{
XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
}
}
Private Sub InvokePrint(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Create the print dialog object and set options
Dim pDialog As New PrintDialog()
pDialog.PageRangeSelection = PageRangeSelection.AllPages
pDialog.UserPageRangeEnabled = True
' Display the dialog. This returns true if the user presses the Print button.
Dim print? As Boolean = pDialog.ShowDialog()
If print = True Then
Dim xpsDocument As New XpsDocument("C:\FixedDocumentSequence.xps", FileAccess.ReadWrite)
Dim fixedDocSeq As FixedDocumentSequence = xpsDocument.GetFixedDocumentSequence()
pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job")
End If
End Sub
使用者可以使用 [ 列印 ] 對話方塊來選取印表機、設定印表機,以及執行列印工作。
嚴格來說,您可以使用 PrintDocument 方法,而不需要開啟對話方塊。 如此一來,控制項就可以當做看不到的列印元件使用。 但基於效能考慮,最好是使用 AddJob 方法或 其中 Write 一個 和 WriteAsync 方法 XpsDocumentWriter 。 如需詳細資訊,請參閱 如何:以程式設計方式列印 XPS 檔案。
請勿將這個類別 System.Windows.Controls.PrintDialog 與 System.Windows.Forms.PrintDialog 混淆。 後者會與Windows Forms應用程式搭配使用。 System.Windows.Controls.PrintDialog會與Windows Presentation Foundation應用程式搭配使用。
Print |
初始化 PrintDialog 類別的新執行個體。 |
Current |
取得或設定值,指出列印目前頁面的選項是否已啟用。 |
Max |
取得或設定頁面範圍所允許之最大頁碼。 |
Min |
取得或設定頁面範圍所允許之最小頁碼。 |
Page |
取得或設定當 PageRangeSelection 設為 UserPages 時要列印的頁面範圍。 |
Page |
取得或設定這個 PageRangeSelection 執行個體的 PrintDialog。 |
Printable |
取得頁面可列印區域高度。 |
Printable |
取得頁面可列印區域寬度。 |
Print |
取得或設定表示所選取之印表機的 PrintQueue。 |
Print |
取得或設定當使用者為目前列印工作按下 [列印] 時,PrintDialog 使用的 PrintTicket。 |
Selected |
取得或設定值,這個值表示列印所選頁面的選項是否已啟用。 |
User |
取得或設定值,這個值表示 [列印] 對話方塊使用者是否可使用選項指定要列印之頁面範圍。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
Print |
列印 DocumentPaginator 物件至目前選取的 PrintQueue。 |
Print |
將從 Visual 類別衍生而來的視覺 (非文字) 物件列印到目前選取的 PrintQueue。 |
Show |
叫用 PrintDialog 作為強制回應對話方塊。 |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
產品 | 版本 |
---|---|
.NET Framework | 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 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |