![](/img/trans.png)
[英]Exception when closing a Win32 dialog box in dll (from WPF application)
[英]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.