簡體   English   中英

如何在 WPF 應用程序中托管 MFC/Win32“打印設置”對話框?

[英]How to host an MFC/Win32 “Print Setup” dialog in a WPF application?

如何在 WPF 應用程序中托管 MFC/Win32“打印設置”對話框?

請嘗試以下代碼

在運行時創建 PrintDialog 控件很簡單。 第一步是創建 PrintDialog class 的實例,然后調用 ShowDialog 方法。 下面的代碼片段創建一個 PrintDialog 控件。

PrintDialog PrintDialog1 = newPrintDialog();  
PrintDialog1.ShowDialog(); 

PrintDocument object 表示要打印的文檔。 創建 PrintDocument 后,我們可以將 PrintDialog 的 Document 屬性設置為該文檔。 之后我們還可以設置其他屬性。下面的代碼片段創建了一個 PrintDialog 並將一些文本發送到打印機。

privatevoid PrintButton_Click(object sender, EventArgs e) {  
    PrintDialog printDlg = newPrintDialog();  
    PrintDocument printDoc = newPrintDocument();  
    printDoc.DocumentName = "Print Document";  
    printDlg.Document = printDoc;  
    printDlg.AllowSelection = true;  
    printDlg.AllowSomePages = true;  
    //Call ShowDialog  
    if (printDlg.ShowDialog() == DialogResult.OK) printDoc.Print();  
}  

You could use the winforms printdialog by adding a reference to System.Windows.Forms or dllimport the one in comdlg32.dll An example call can be found here: http://www.pinvoke.net/default.aspx/comdlg32.PrintDlg

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM