How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

Visual Studio 2013

Visual Studio 2013

Visual Studio 2013 is now available. Make sure to upgrade to the latest version of Visual Studio. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »

 

Turn monitor on/off in C#

The following snippet will allow you to change your monitor’s state to either off/on or standby mode. Unlike other methods this one works on Windows 7 as well (tested under Windows 7 64bit).

The first step is to include in your class the following code:

This will allow us to send a WM_SYSCOMMAND message using SendMessage to alter the state of the monitor.

Finally, add the method which we will be calling when we want to change the monitor’s state:

Simply call the SetMonitorState method with the desirable state you want to change your monitor’s state to.

Usage:

Keep in mind that the SC_MONITORPOWER commands supports devices that have power-saving features, so depending on the monitor’s brand/drivers/firmware results might vary.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

One Response to Turn monitor on/off in C#

  1. Gabor says:

    Hi, I want to switch only my secondary monitor, not the main desktop.
    How can i send the command to this?
    How can i get the handle for each in multi monitor system?

Leave a Reply

Your email address will not be published. Required fields are marked *