设置
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!--<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor</dpiAwareness>-->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
</windowsSettings>
</application>
获取虚拟屏幕的尺寸的三种方式
通过api获取
int left = GetSystemMetrics(SM_XVIRTUALSCREEN);
int top = GetSystemMetrics(SM_YVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
通过winform获取
int width3 = SystemInformation.VirtualScreen.Width;
int height3 = SystemInformation.VirtualScreen.Height;
通过wpf获取
double height1 = SystemParameters.VirtualScreenHeight;
double width1 = SystemParameters.VirtualScreenWidth;
坑
- dpi不为100%时, 当没有设置 以下代码的时候,不管是通过api,还是通过winform、wpf获取到的虚拟屏幕的高度都不正确, 所以必须设置以下代码
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> </windowsSettings>
网友评论