1

Is there a way to make make a windows form application full screen and black out your secondary monitors? So the main display is on your primary display and all your other monitors are just completely black?

MBU
  • 4,998
  • 12
  • 59
  • 98
  • I'm just curious if this is for a side project or something for work. If it's for a side project, then one bit of feedback: I can't want to find a solution for this problem because I would hate an app to do this. I can turn off the other monitor if I want it to be black, but I often want something else there. If it's for work there's probably no helping it. – Jeremy Pridemore Jun 18 '12 at 22:10
  • You can certainly interact with the monitors via C# - see http://stackoverflow.com/questions/233411/how-do-i-enable-a-second-monitor-in-c-sharp or http://fci-h.blogspot.co.uk/2007/03/turn-off-your-monitor-via-code-c.html. As for running an app in full screen mode - take a look at "Kiosk Mode" - for example, http://www.codeproject.com/Articles/23955/Running-a-Web-Site-in-Kiosk-Mode-with-C. You could also point IE at a url hosting a winforms app (iexplore -k url) - http://www.visualwebgui.com/Developers/KB/tabid/654/article/running_a_winforms_application_inside_your_web_browser/Default.aspx – dash Jun 18 '12 at 22:12

3 Answers3

4

You can use the Screen class which give you informations about the current active screens.

// Form myFrm
Rectangle r = new Rectangle();
foreach (Screen s in Screen.AllScreens)
{
   if ( s != Screen.CurrentScreen ) // Blackout only the secondary screens
         r = Rectangle.Union(r, s.Bounds);
}
myFrm.Top = r.Top;
myFrm.Left = r.Left;
myFrm.Width = r.Width;
myFrm.Height = r.Height;
myFrm.TopMost = true; // This will bring your window in front of all other windows including the taskbar
Samy Arous
  • 6,794
  • 13
  • 20
  • That would end up blacking out the main screen as well, if it is a three-monitor setup with the primary in the middle. – David Yaw Jun 18 '12 at 22:26
  • True, but in this case, it's not easy to do that using one single form (Technically it is possible, using Regions). This method can be used to generate one form by screen. – Samy Arous Jun 18 '12 at 22:29
1

I can think of one way, and that would be to find out how many monitors there are on the computer, and their layout relative to each other, then create your primary window at 0,0, maximize it and set it to be TopMost, then do the same for the other displays, placing them at the screen locations corresponding to the top left of each monitor of the computer.

The only thing I can think of that would benefit from this in a WinForms environment is an app designed to give a test; the app would cover the entire desktop (except the taskbar; you'd have to disable the Start menu) and pretty much ensure that the user couldn't look at anything except the testing program. It will give you a minimal performance advantage.

Most of the apps that black out all the monitors except the main display are basically using DirectX to control the screen directly (through the lower-level interface to the graphics card). If you're using WinForms to make your program, you're about 50 levels of abstraction above using DirectX.

KeithS
  • 70,210
  • 21
  • 112
  • 164
0

One way would be to create a second form in your application. One that, when given a set of dimensions, will open without border or menu and with the background set to black.

When your application runs, enumerate your monitors (count them to see how many) and find their dimensions. Your primary one will start at 0,0. Then spawn a copy of that second form for each of your monitors (except your primary one) and give that form the dimensions of the monitor. They will then turn each screen black.

You will need to remember to keep a handle to each of the forms and terminate them when you terminate your main form.

Buzby
  • 345
  • 1
  • 11