設(shè)置
<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%時蜀肘, 當(dāng)沒有設(shè)置 以下代碼的時候酌予,不管是通過api磺箕,還是通過winform、wpf獲取到的虛擬屏幕的高度都不正確抛虫, 所以必須設(shè)置以下代碼
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> </windowsSettings>