我想为不同的显示器设置不同的屏幕尺寸。
分辨率
主要 - 1600*900,
辅助 - 1920*1080
我的应用程序在主屏幕上运行良好,但是当我将应用程序拖动到辅助屏幕上并最大化时,它仅根据主屏幕高度最大化。
我想要应用程序屏幕尺寸与当前屏幕一致。
最佳答案
我建议您使用System.Windows.Forms
中的Screen
类来定义您的应用程序是否在第二个屏幕上。有必要知道用户何时将您的应用程序移动到第二个显示器,为了了解这一点,我使用 LocationChanged
事件:
隐藏代码:
private Screen GetSecondaryScreen()
{
foreach (Screen screen in Screen.AllScreens)
{
if (screen != Screen.PrimaryScreen)
return screen;
}
return Screen.PrimaryScreen;
}
private void Window_LocationChanged(object sender, EventArgs e)
{
if (Screen.PrimaryScreen != GetSecondaryScreen())
{
this.WindowState = WindowState.Maximized;
}
}
XAML:
<Window x:Class="DateTimePickerDataGridWPF.MainWindow"
...the code omitted for the brevity...
Title="MainWindow" Height="350" Width="525" LocationChanged="Window_LocationChanged">
</Window>
关于c# - 在辅助监视器上最大化时设置 wpf 应用程序屏幕高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36619461/