在最大化的辅助监视器上设置WPF应用程序屏幕高度 [英] Set wpf application screen height on secondary monitor on maximize

查看:81
本文介绍了在最大化的辅助监视器上设置WPF应用程序屏幕高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为不同的显示器设置不同的屏幕尺寸.

解决方案

主要-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>   

I want to set up different screen sizes for Different Monitors.

Resolution

primary - 1600*900,

secondary - 1920*1080

My application is working fine on primary screen, but when i drag the application on secondary screen and maximize ,it maximize only as per primary screen height.

I want the application screen size as per current screen.

解决方案

I suggest you to use Screen class from System.Windows.Forms to define whether your application is on the second screen. It is necessary to know when a user moves your application to the second display and to know it, I use LocationChanged event:

Code-behind:

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>   

这篇关于在最大化的辅助监视器上设置WPF应用程序屏幕高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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