WPF:为什么获取 PrintDialog 的 .PrintableAreaWidth 和 .PrintableAreaHeight 太慢? [英] WPF: Why TOO SLOW to Get PrintDialog's .PrintableAreaWidth and .PrintableAreaHeight?

查看:44
本文介绍了WPF:为什么获取 PrintDialog 的 .PrintableAreaWidth 和 .PrintableAreaHeight 太慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常有线的 WPF PrintDialog 问题 -- Windows XP64 + VS2010.

I am experiencing an extremely wired WPF PrintDialog issue -- Windows XP64 + VS2010.

令人难以置信的是,获取 PrintDialog 的 .PrintableAreaWidth 或 .PrintableAreaHeight 属性非常非常慢.

It is pretty unbelievable that it is very very slow to get PrintDialog's .PrintableAreaWidth or .PrintableAreaHeight property.

//参见下面的示例代码 - 记住包括使用 System.Windows.Controls"

// see sample codes below - remember to include "using System.Windows.Controls"

PrintDialog pd = new PrintDialog();
double pw = pd.PrintableAreaWidth;    // set a break-point here, very slow, why???  
double ph = pd.PrintableAreaHeight;

有人对此有任何想法吗?我感谢任何想法!

Anyone has any idea regarding this? I appreciate any thoughts!

推荐答案

PrintableArea 指的是实际使用的打印机 - 您的应用必须联系打印机才能获取该信息,我的猜测是这就是为什么它很慢的原因.在 WinForms 中它不应该更快...

The PrintableArea refers to the actual Printer in use - your app has to contact the printer to get that info, and my guess is that's the reason why it's slow. It shouldn't be any faster in WinForms...

如果您想优化,您可以缓存打印机名称及其默认值,然后使用它而不是每次都查询打印机.

If you'd want to optimize, you could cache the printer name and it's defaults and use that instead of querying the printer each time.

这篇关于WPF:为什么获取 PrintDialog 的 .PrintableAreaWidth 和 .PrintableAreaHeight 太慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆