[C#] 모니터 off 하기
public partial class MainForm : Form
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MONITORPOWER = 0xF170;
const int MONITOR_ON = -1;
const int MONITOR_OFF = 2;
const int MONITOR_STANBY = 1;
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
Console.WriteLine(this.Handle.ToInt32());
int ScreenHeight = 0;
System.Windows.Forms.Screen[] screens = System.Windows.Forms.Screen.AllScreens;
if (screens.Length >= 1)
{
foreach (Screen screen in screens)
{
if (screen.Primary)
{
ScreenHeight = screen.Bounds.Height;
Console.WriteLine(ScreenHeight);
}
}
}
else
{
ScreenHeight = screens[0].Bounds.Height;
}
}
// 모니터 Off
private void button1_Click(object sender, EventArgs e)
{
SendMessage(this.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
}
}