views:

521

answers:

3

I've had a bit of a search around, but couldn't find anything similar to what I was looking for. I'm interested in knowing how to display differing contents on secondary/tertiary monitors or projectors using C#. Basically, what I'm wanting to achieve is to have some form of presenter view (a lá Powerpoint) on one particular screen (the primary display), and the output on a secondary screen or projector. I've never really attempted to develop something with multiple display outputs, so any guidance will probably have to be at a fairly obvious level.

If someone could point me in the right direction as to how to handle this sort of thing in C#, that would be greatly appreciated!

+2  A: 

You can use the System.Windows.Forms.Screen.AllScreens property to access a list of all the monitors Windows knows about. If you're looking to utilize a display that hasn't been configured by the user, it gets more difficult - you'd probably need to initialize and access the display adapter using DirectX.

Kevin Gadd
As a way of a related sub-question: how, then, is it best to display a full-screen output on one display, and retain control in another display? I know from using other full-screen applications on a multi-monitor setup, if you try to click elsewhere, you end up with the full-screen application losing focus and minimising itself. How should I be working around this - or is this not an issue in the approach you've described? (I'm not able to test at the moment.)
James Burgess
The simplest approach would be to create a full-screen window and set it to TopMost, using the information from the AllScreens collection to position it. Then you don't have the problem traditionally seen with single-monitor fullscreen applications (where they minimize themselves on loss of focus.)
Kevin Gadd
Thanks a bunch, I'll give this a try :)
James Burgess
+1  A: 

One of the main classes you will need to interact with is Screen (this is in the WinForms namespace). In general all the screens are treated as a set of working areas that you can use the screen class to get properties for each one.

You can get all the screens like this...

Screen [] screens = Screen.AllScreens;

Here is a short article about doing multi-monitor programming in C#.

Brian ONeil
+2  A: 

Just to expand on Keven's answer (I +1'd it), The Screen.AllScreens array gives you have an array of Screen objects. The Screen object has a property called IsPrimary, which you can use to determine which is the primary screen, and which is the secondary (duh) and it also has a property called WorkingArea, which is a rectangle that gives you back all the coordinates of the second screen. The cool thing about this is, that even if let's say the secondary screen is configured to be on the left of the primary, the WorkingArea.X will be a negative number, and you can place forms there or whatever.

BFree