WPF 当前屏幕尺寸 [英] WPF Current Screen Dimensions

查看:33
本文介绍了WPF 当前屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我所有的应用程序中,如果我想根据当前的显示器分辨率调整窗口大小,我使用以下方法:

Throughout all my applications, if I wish to size a window according to the current monitor resolution I use the following:

     System.Drawing.Rectangle workingArea = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(App.Current.MainWindow).Handle).WorkingArea;

但是,我有一个使用多台显示器的客户,但这是行不通的.调整大小的窗口跨越到第二台显示器.只有这一个客户.我已经使用多台显示器对此进行了测试,效果很好.

However, I have one client, who uses multiple monitors, where this is just not working. The resized window is spanning across to a second monitor. Only this one client. I've tested this using multiple monitors and it works fine.

有人可以建议更好/替代的方法吗?

Can anyone please suggest a better/alternative method?

推荐答案

对于任何 FrameworkElement 你可以得到它的渲染大小(HeightWidth>) 使用这个.

For any FrameworkElement you can get it's rendered size (Height and Width) by using this.

FrameworkElement.ActualWidth;
FrameworkElement.ActualHeight;

所以在这种情况下,您可以将它用于您的窗口.

so in this case you can use it for your window.

这篇关于WPF 当前屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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