【发布时间】:2015-04-23 06:35:16
【问题描述】:
我的应用程序支持 DPI,这是完整的清单:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity name="SlackUI"
type="win32"
version="1.0.0.0" />
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</asmv1:assembly>
我正在设置我的NotifyIcon 图标属性,如下所示:
notifyIcon.Icon = new Icon(Program.Settings.Data.WhiteNotificationIcon ?
Properties.Resources.NotifyWhite : Properties.Resources.NotifyColor, SystemInformation.SmallIconSize)
但是,这不适用于我的 Windows 8.1 系统上等于或高于 150% 的 DPI 缩放。当它设置为 100% SystemInformation.SmallIconSize 时报告 16x16 大小(正确),当它设置为 125% 时它报告 20x20 大小(正确),在此之上,例如 150%,它应该报告 24x24 大小,而是报告 16x16 并加载我的图标文件中的分辨率错误。
阅读以下文章 (http://blog.quppa.net/2011/01/07/small-icon-size-dpi-in-windows/) 它告诉我...
WPF 和 WinForms 都围绕着 Win32 GetSystemMetrics 函数 采用参数 SM_CXSMICON(小图标宽度)和 SM_CYSMICON (小图标高度)。
这意味着可能不需要我自己打电话给GetSystemMetrics,对吧?
知道如何解决这个问题吗?
P.S:我说的是我正在开发的一个开源应用程序,所以如果你想仔细查看完整的源代码,你可以这样做here。
【问题讨论】:
-
强烈暗示您的清单实际上没有发挥作用。您可以调用 IsProcessDPIAware() 进行仔细检查。注意 Visual Studio 托管过程,使用 Project + Properties、Debug 选项卡将其关闭。
-
@HansPassant 我添加了
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern bool IsProcessDPIAware();,它一直返回true,即使我删除了整个清单文件。
标签: c# .net notifyicon dpi-aware