.net - 在辅助显示器上全屏显示

标签 .net wpf windows fullscreen multiple-monitors

如何编写一个 dotNet Windows(或 WPF)应用程序,以便让它在辅助显示器上全屏显示?

最佳答案

将窗口最大化到辅助监视器(如果有的话)的扩展方法。 不假定辅助监视器是 System.Windows.Forms.Screen.AllScreens[2];

using System.Linq;
using System.Windows;

namespace ExtendedControls
{
    static public class WindowExt
    {

        // NB : Best to call this function from the windows Loaded event or after showing the window
        // (otherwise window is just positioned to fill the secondary monitor rather than being maximised).
        public static void MaximizeToSecondaryMonitor(this Window window)
        {
            var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();

            if (secondaryScreen != null)
            {
                if (!window.IsLoaded)
                    window.WindowStartupLocation = WindowStartupLocation.Manual;

                var workingArea = secondaryScreen.WorkingArea;
                window.Left = workingArea.Left;
                window.Top = workingArea.Top;
                window.Width = workingArea.Width;
                window.Height = workingArea.Height;
                // If window isn't loaded then maxmizing will result in the window displaying on the primary monitor
                if ( window.IsLoaded )
                    window.WindowState = WindowState.Maximized;
            }
        }
    }
}

关于.net - 在辅助显示器上全屏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/753552/

相关文章:

c# - ClickOnce 在重新安装期间不替换 App_Data 文件

c# - 图形 DrawImage 导致带有大红色 X 的错误

c# 在数据库中存储用户设置

c# - 从 FileStream 获取原始路径

C# + CaSTLe ActiveRecord : HasAndBelongsToMany and collections

c++ - 从 .dll 访问 .exe 中定义的函数的正确方法

windows - 在批处理文件中以管理员身份复制文件

c# - 使用 LinqtoEntities lambda C# 选择项目

c# - 如何在 WPF 中创建垂直菜单并在菜单右侧创建子菜单?

c# - 如何为 FlowDocumentScrollViewer 的自动滚动创建附加行为