Click here to Skip to main content
Click here to Skip to main content

Multi-monitor programming in C#

, 20 Mar 2004
Rate this:
Please Sign up or sign in to vote.
How to discover and use multiple monitors.

Introduction

Using multiple monitors in C# is actually a rather simple job since the monitors are combined to one big rectangle to draw on. But you can also use one single monitor if you like.

In this article, I will give a brief explanation of how to discover how many monitors the user has and how high the resolution of each monitor is.

Where do I find the right information?

The right information about monitors can be found in the Screen class of System.Windows.Forms namespace. In this class, you can find all sorts of information about how many monitors there are, and the working area of each monitor. Also, the device name can be recovered from this class.

Discovering the number of monitors

This is pretty simple. In the Screen class, you will find a property called AllScreens. This is an array of Screen objects which represent the monitors of your system. If you use the Length property of this array, you will find the number of monitors connected to your system.

The rest of the information

At each index in the array, there is a Screen class which contains the following information:

  • DeviceName
  • WorkingArea
  • Bounds
  • Primary

The DeviceName looks like this: \\.\DISPLAY1. This can be used in combination with various Windows API calls, which I won't explain here. The WorkingArea is the actual area that can be used to display graphical data, like Windows forms and other things. This area is calculated out of the Bounds minus the size of Windows taskbar. The Bounds property is the actual resolution that the monitor currently has. The Primary property is false when the screen isn't the primary one. If it is the primary screen, this property will return true.

How to discover the current screen

You can check at what screen your at, using a simple piece of code:

Screen scrn = Screen.FromControl(this);

What's in my demonstration

In the source code, you will find a small project that demonstrates all the functions explained in this article. If you compile and run the project, you can move the form from one screen to another, and the application will give the information about the screen you are at.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

WillemM
Web Developer
Netherlands Netherlands
----

Comments and Discussions

 
QuestionMultiple Monitors as Independent Displays PinmemberMember 108035426-Jul-14 16:09 
GeneralMy vote of 4 PinmemberMember 431244716-Nov-13 18:52 
QuestionCan anyone help me on this? Pinmembercaribou2us17-Jul-13 17:38 
GeneralMy vote of 1 PinmemberZejulioZ22-May-11 22:40 
General[My vote of 1] Useless Pinmemberkingfedaikyn7-Apr-11 2:57 
GeneralMy vote of 5 PinmemberAvi Farah17-Nov-10 6:23 
Thank you
GeneralGreat Contribution PinmemberCarlosReinoza16-Aug-10 16:41 
GeneralMy vote of 1 PinmemberOreshkov Sergey15-Apr-10 22:10 
GeneralRe: My vote of 1 PinmemberMasterOfCodeproject8-Dec-10 1:16 
GeneralExcellent Pinmemberpbne047-Apr-10 0:21 
QuestionMultiple outputs for multiple monitors Pinmembermuralikrishnas16-Dec-08 0:34 
GeneralRe: Multiple outputs for multiple monitors Pinmemberrev4eva5-Apr-09 17:06 
QuestionActive or not active? PinmemberLofote18-Aug-05 4:07 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 21 Mar 2004
Article Copyright 2004 by WillemM
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid