外出全屏辅助监视器上 [英] Going fullscreen on secondary monitor
本文介绍了外出全屏辅助监视器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你怎么能方案,以一个dotNet的Windows(或WPF)应用程序,让它外出时的全屏辅助监视器上?
How can you program a dotNet Windows (or WPF) Application in order to let it going fullscreen on the secondary monitor?
推荐答案
扩展方法,以最大化的窗口来辅助监视器(如果有的话)。 不假定辅助显示器是System.Windows.Forms.Screen.AllScreens [2];
Extension method to Maximize a window to the secondary monitor (if there is one). Doesn't assume that the secondary monitor is 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;
}
}
}
}
这篇关于外出全屏辅助监视器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文