HOW TO:建立和顯示 PrintDialog
更新:2007 年 11 月
本範例示範如何顯示 PrintDialog 方塊。
範例
下列範例示範如何藉由以下方式顯示列印對話方塊:
執行個體化 PrintDialog。
藉由設定 PageRangeSelection 和 UserPageRangeEnabled 屬性來設定頁面範圍選取範圍選項。
呼叫 ShowDialog 方法來顯示列印對話方塊。
<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 == true)
{
XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
}
}
如需完整範例,請參閱 PrintDialog 範例。