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 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
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.