Turn Off Your Monitor

sandeepparekh9 4 Tallied Votes 227 Views Share

Turn you Monitor off from your application.

public partial class Form1 : Form
    {
        public int WM_SYSCOMMAND = 0x0112;
        public int SC_MONITORPOWER = 0xF170; 
        [DllImport("user32.dll")]
        private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendMessage( this.Handle.ToInt32() , WM_SYSCOMMAND , SC_MONITORPOWER ,2 );//DLL function
        }
    }
jfarrugia 6 Junior Poster

nice!!

Joshua Kidd 0 Junior Poster

Thats cool.

samee1985 0 Newbie Poster

it does not work
please help.

Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?) E:\Windows Application\TEST APPLICATION\TurnOffMonitor\TurnOffMonitor\Form1.cs 19 10 TurnOffMonitor

bhagawatshinde 11 Posting Whiz

use namespace

using System.Runtime.InteropServices;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.