Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Multi-monitor programming in C#

0.00/5 (No votes)
20 Mar 2004 1  
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