C# – Turn on/off monitor


Is it programmatically possible to turn a monitor on/off through code (C#)?

Best Solution

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 February 8th 2013:

It was mentioned that the solution no longer worked under Windows 7 en 8. Well here is one that works nicely under Windows 7, haven't tried Windows 8 yet.


namespace MonitorOff {

    public enum MonitorState {
        MonitorStateOn = -1,
        MonitorStateOff = 2,
        MonitorStateStandBy = 1

    public partial class Form1 : Form {
        private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);

        public Form1() {
            SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

        void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e) {

        private void button1_Click(object sender, EventArgs e) {

        private void SetMonitorInState(MonitorState state) {
            SendMessage(0xFFFF, 0x112, 0xF170, (int)state);
Related Question