PrintDialog.ShowDialog(this) 在 Windows 7 上立即返回 DialogResult.Cancel

发布于 2024-08-11 10:18:20 字数 584 浏览 1 评论 0原文

我正在开发的内部应用程序在 Windows 7(64 位)PC 上表现奇怪。

如果我创建 PrintDialog 的实例,并调用它的 ShowDialog() 方法,该方法会立即返回 DialogResult.Cancel,而不显示打印机对话框窗体。

Windows 7 PC 确实安装了打印机(具有正常工作的默认打印机)。

PrintDialog printDialog = new PrintDialog();

printDialog.PrinterSettings.Copies = 2;
printDialog.AllowCurrentPage = false;
printDialog.AllowPrintToFile = false;
printDialog.AllowSelection = false;
printDialog.AllowSomePages = false;
DialogResult dialogResult = printDialog.ShowDialog(this);

if (dialogResult == DialogResult.Cancel)
    return;

有任何线索为什么会发生这种情况吗?

An in house application that I'm developing is behaving strange on a Windows 7 (64 bit) PC.

If I create an instance of a PrintDialog, and call it's ShowDialog() method, the method immediately returns DialogResult.Cancel without showing the printer dialog form.

The Windows 7 PC does have printers installed (with a working default printer).

PrintDialog printDialog = new PrintDialog();

printDialog.PrinterSettings.Copies = 2;
printDialog.AllowCurrentPage = false;
printDialog.AllowPrintToFile = false;
printDialog.AllowSelection = false;
printDialog.AllowSomePages = false;
DialogResult dialogResult = printDialog.ShowDialog(this);

if (dialogResult == DialogResult.Cancel)
    return;

Any clues why this is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗梦空间 2024-08-18 10:18:20

printDialog.UseEXDialog 设置为 true 以解决此错误。

在 .Net 3.5 中,MSDN 在记录 UseEXDialog 时提到了这个潜在问题

当此属性设置为 true 时,ShowHelpShowNetwork 将被忽略,因为这些属性在 Windows 2000 及更高版本中已过时Windows 的。 此外,PrintDialog 类可能无法在 AMD64 微处理器上运行,除非将 UseEXDialog 属性设置为 true

(我的强调。)

.Net 4.Net 4.5 不包括强调的位,所以也许它在这些版本中已修复。

Set printDialog.UseEXDialog to true to work around this bug.

In .Net 3.5, MSDN mentions this potential problem when documenting UseEXDialog:

When this property is set to true, ShowHelp and ShowNetwork will be ignored as these properties were made obsolete for Windows 2000 and later versions of Windows. Also, The PrintDialog class may not work on AMD64 microprocessors unless you set the UseEXDialog property to true.

(My emphasis.)

The same page for .Net 4 and .Net 4.5 don't include the emphasized bit, so perhaps it's fixed in those versions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文