WPF文檔打印代碼示例講解
作者:佚名
WPF文檔打印是一個(gè)比較基礎(chǔ)的應(yīng)用技術(shù)。在初級(jí)開發(fā)人員中,掌握這一技術(shù)是非常有必要的。我們可以在實(shí)踐中去牢固我們所學(xué)到的知識(shí)。
WPF的應(yīng)用,可以幫助我們簡單的實(shí)現(xiàn)MAC一樣的圖形界面效果。而且其應(yīng)用范圍也是比較廣泛的。在這里就為大家介紹一下WPF文檔打印的相關(guān)實(shí)現(xiàn)方法。#t#
WPF文檔打印XAML代碼:
- < Button Width="200"
Click="InvokePrint">
Invoke PrintDialog< /Button>
WPF文檔打印C#代碼:
- string printFileName =
@"C:\TestForPrint.xps"; - public void InvokePrint
(object sender, Routed
EventArgs e) - {
- // 打印對(duì)話框,設(shè)置屬性
- PrintDialog pDialog =
new PrintDialog(); - pDialog.PageRangeSelection =
PageRangeSelection.AllPages; - pDialog.UserPageRangeEnabled
= true; - // 這里你還可以設(shè)置對(duì)話框的MaxPage,
MinPage, PageRange, Printable
AreaHeight, PrintableAreaWidth,
PrintQueue, PrintTicket屬性值等。 - // 顯示對(duì)話框,如果用戶點(diǎn)擊“打印”
按鈕,則返回true。 - Nullable< Boolean> print =
pDialog.ShowDialog(); - if (print == true)
- {
- XpsDocument xpsDocument =
new XpsDocument(printFileName,
FileAccess.ReadWrite); - FixedDocumentSequence fixedDocSeq =
xpsDocument.GetFixedDocumentSequence(); - pDialog.PrintDocument(fixedDocSeq.Do
cumentPaginator, "Test print"); - }
- }
以上這段代碼示例就是WPF文檔打印的實(shí)現(xiàn)方法。
責(zé)任編輯:曹凱
來源:
CSDN