views:

1170

answers:

3

How can you program a dotNet Windows (or WPF) Application in order to let it going fullscreen on the secondary monitor?

+6  A: 

See this codeproject article.

The code in there will work, but default to your primary monitor. To change this, you'll need to replace the calls to GetSystemMetrics will calls to GetMonitorInfo. Using GetMonitorInfo, you can get the appropriate RECT to pass to SetWindowPos.

GetMonitorInfo allows you to get the RECT for any monitor.

There is an MSDN Article on Position Apps in Multi-Monitor Setups that might help explain things a bit better.

Reed Copsey
+2  A: 
private void Form1_Load(object sender, EventArgs e)
{
   this.FormBorderStyle = FormBorderStyle.None;
   this.Bounds = GetSecondaryScreen().Bounds;
}

private Screen GetSecondaryScreen()
{
   foreach (Screen screen in Screen.AllScreens)
   {
      if (screen != Screen.PrimaryScreen)
         return screen;
   }
   return Screen.PrimaryScreen;
}
Pavel Chuchuva
This works but requires a reference to System.Windows.Forms.dll
Rick Ratayczak
A: 

It's not clear from your question if you are looking for a way to move the window to the secondary monitor and then go fullscreen, or if you are just looking to support fullscreen mode on whatever monitor the window is on (which may be primary or secondary).

If the later, for a WPF window, though not quite the same as fullscreen mode, you can remove the borders when it is maximized and restore the border when not maximized. No need to check for which monitor, etc. The display of the caption/title bar is controlled by the border state.

    protected override void OnStateChanged(EventArgs e)
    {
        if (WindowState == WindowState.Maximized)
        {
            if (WindowStyle.None != WindowStyle)
                WindowStyle = WindowStyle.None;
        }
        else if (WindowStyle != WindowStyle.SingleBorderWindow)
            WindowStyle = WindowStyle.SingleBorderWindow;

        base.OnStateChanged(e);
    }

Credit goes to Pavel for his Forms-based answer in the current question and to Nir for his answer in this question.

sean e