VSTO 加载项中的 SetProcessDPIAware [英] SetProcessDPIAware in VSTO add-in

查看:31
本文介绍了VSTO 加载项中的 SetProcessDPIAware的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网上有很多关于通过调用 SetProcessDPIAware()(或通过对应用程序的清单进行一些相关更改)来为 Winforms 应用程序设置 DPI 感知的帖子.例如:

There are a lot of posts online about setting DPI awareness for a Winforms application by calling SetProcessDPIAware() (or by making some related changes to the application's manifest). For example:

如何将应用配置为在具有高 DPI 设置(例如 150%)的机器上正确运行?

但是,我不确定在 Excel、PowerPoint 等的 VSTO 加载项中如何以及在何处调用 SetProcessDPIAware().虽然,但无法使其正常工作,因为加载项的各种 Winform 仍然无法在高 DPI 显示器上正确缩放.

However, I am unsure how and where to call SetProcessDPIAware() in a VSTO add-in for Excel, PowerPoint, etc. I have experimented with this for a while, but cannot get it working as the add-in's various Winforms are still not scaling correctly on high-DPI displays.

谁能提供有关如何在 VSTO 加载项中实现 DPI 感知的指导,特别是?

Can anyone provide guidance on how to implement DPI awareness in VSTO add-ins, specifically?

推荐答案

您不能在此处影响 DPI 感知,因为这是每个进程的设置,而您的进程是 Excel 本身(即 DPI 感知).您只能在您的程序调用第一个 DPI 相关的 Windows 函数之前使用 SetProcessDPIAware() 函数,Excel 甚至在您的加载项启动之前很久就这样做了.但是,当启用 DPI 感知时,不要指望 Winforms 像魔术一样正确缩放.启用 DPI 意识无非是:打开潘多拉的盒子,打开 Winforms 为您提供的所有令人讨厌的高 DPI 效果的盒子.您将不得不自己摆弄控制距离和尺寸.来自微软官方的声明:如果你想要 DPI 意识,不要使用 Winforms,使用 WPF如果你要Touch,不要用WPF,用UWP...

You can't influence DPI awareness here, because this is a per-process setting, and your process is Excel itself (which is DPI aware). You can only use the SetProcessDPIAware() function only before your program calls the first DPI related Windows function, which Excel did long before your Add-In even started. However, don't expect Winforms to scale correctly as magic when DPI awareness ist enabled. Enabling DPI awareness means nothing more than: Opening the box of pandora for all the nasty High DPI effects Winforms offers for your pleasure. You will have to fiddle around with control distances and sizes yourself. Statement from a Microsoft official: If you want DPI awareness, don't use Winforms, use WPF If you want Touch, don't use WPF, use UWP...

这篇关于VSTO 加载项中的 SetProcessDPIAware的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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