Click here to Skip to main content
Licence CPOL
First Posted 4 Jan 2008
Views 13,664
Downloads 122
Bookmarked 20 times

Multiple monitor management

By | 4 Jan 2008 | Article
How to manage multiple monitors.

Introduction

This code is a simple test to move a Windows Forms application to anywhere in a multiple monitor environment.

Using the code

At application startup, the program takes the screen names.

for (int i = 0; i < Screen.AllScreens.Length; i++)
{
    cbMonitor_id.Items.Add(Screen.AllScreens[i].DeviceName);
}

You can put any location (CoodX-CoordY) and the desired screen, then when you press the button, the application executes.

SetMonitor(this, ((cbMonitor_id.SelectedIndex>-1)?cbMonitor_id.SelectedIndex:0), 
   System.Convert.ToInt32(edCoordX.Text), System.Convert.ToInt32(edCoordY.Text));

And here is the display code:

void SetMonitor(Form form, int monitor_id, int x, int y)
{
    Screen screen = Screen.AllScreens[monitor_id];
    // Set the StartPosition to Manual otherwise
    // the system will assign an automatic start position
    form.StartPosition = FormStartPosition.Manual;
    // Set the form location so it appears at Location (x, y)
    // on the screen monitor_id
    x = screen.Bounds.Location.X + x;
    y = screen.Bounds.Location.Y + y;
    form.Location = new Point(x,y);
    // Show the form
    form.Show();
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

nauchititi



Spain Spain

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralRefresfing only # 2 display PinmemberSteve Landsaw13:16 27 Mar '08  
QuestionAdvice PinmemberHIDDENS1:55 4 Jan '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 4 Jan 2008
Article Copyright 2008 by nauchititi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid