Is it programmatically possible to turn a monitor on/off through code (C#)?
Press the on/off button
If you want to do it in code, apparently this is possible in the Win32 API:
SendMessage hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, param
where WM_SYSCOMMAND = 0x112 and SC_MONITORPOWER = 0xF170 and param indicates the mode to put the monitor in: -1 : on 2 : off 1 : energy saving mode
hWnd can be a handle for any window - so if you have a Form, something like this should work
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
public static void Main(string[] args)
{
Form f = new Form();
bool turnOff; //set true if you want to turn off, true if on
SendMessage(f.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, turnOff ? 2 : -1);
}
Note I haven't actually tried this...
Did you even try googling it?
First hit: http://www.codeproject.com/KB/cs/Monitor_management_guide.aspx
I am not surprised you need to use some DLL's supplied by Windows.
(I guessed you needed a C# solution, because that's the only tag you applied).
Edit: I tested this in a quick app and all seems to work nicely. This should solve your problems.
Actually, it appears you can in C#: http://fci-h.blogspot.com/2007/03/turn-off-your-monitor-via-code-c.html. Haven't tested this, though.
You could use one of these to control the monitor. They have .NET assemblies available to get up and running quickly.
I can see this functionality finding its way into my custom inventory agent that i use at the company i work for.
It would be fun to put peoples monitors in sleep mode randomly while i watch from a distance listening to the "WTF!?!"