4

i have a dual monitor setup and i want my c# application to maximize its window on a specific Screen.

how can i do that?

thanks!

clamp
  • 33,000
  • 75
  • 203
  • 299

4 Answers4

4

This is a screen management code for a similar scope in one of my projects:

        // screenId in my case is 1(first) or 2(second)
        int screenId = RegistryManager.ScreenId;
        // DualScreen management            
        if (screenId > 0)
        {
            // Have 2 screens
            if (System.Windows.Forms.Screen.AllScreens.Length == 2)
            {
                if (screenId == 1) // first
                    this.Location = new System.Drawing.Point(System.Windows.Forms.Screen.AllScreens[0].Bounds.Left, 0);
                else // second
                    this.Location = new System.Drawing.Point(System.Windows.Forms.Screen.AllScreens[1].Bounds.Left, 0);
            }
        }
serhio
  • 28,010
  • 62
  • 221
  • 374
2

You use the Screen class to find the 2nd monitor link

Code found here

function void showOnMonitor2()
{
Screen[] sc;
sc = Screen.AllScreens;
//get all the screen width and heights
Form2 f = new Form2();
f.FormBorderStyle = FormBorderStyle.None;
f.Left = sc[1].Bounds.Width;
f.Top = sc[1].Bounds.Height;
f.StartPosition = FormStartPosition.Manual;
f.Location = sc[1].Bounds.Location;
Point p = new Point(sc[1].Bounds.Location.X, sc[1].Bounds.Location.Y);
f.Location = p;
f.WindowState = FormWindowState.Maximized;
f.Show();
}
RvdK
  • 19,580
  • 4
  • 64
  • 107
  • You'll need some error checking to make sure there is more than 1 screen. – Matt Dec 09 '09 at 16:07
  • Yes i know, this is only a copy paste to show how it works. Any sanity checks should always be applied and checked when using someone else code – RvdK Dec 09 '09 at 16:37
1

You might get this to work by moving the window all the way right or left before maximizing. This should cause the window to maximize to that screen when it does maximize.

Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
0
  Public Shared Sub MoveForm(Item As Form, ScreenNumber As Integer, Optional X As Integer = 0, Optional Y As Integer = 0)
    With Screen.AllScreens(ScreenNumber).Bounds
      X -= .Left 'translate overall coordinates to screen coordinates
      Y -= .Top
    End With
    Item.Location = New System.Drawing.Point(X, Y)
  End Sub
toddmo
  • 20,682
  • 14
  • 97
  • 107