Hack Forums
[.NET] [VB.NET]Turn monitor/screen off[SRC] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [VB.NET]Turn monitor/screen off[SRC] (/showthread.php?tid=1094141)



[VB.NET]Turn monitor/screen off[SRC] - Modestep - Feb 27, 2011

Code
Const ScreenOn = -1&
    Const ScreenOff = 2&
    Const SC_MONITORPOWER = &HF170&
    Const WM_SYSCOMMAND = &H112

    Declare Auto Function SendMessage Lib "user32" ( _
    ByVal hWnd As IntPtr, _
    ByVal Msg As Integer, _
    ByVal wParam As Integer, _
    ByVal lParam As Integer) As Integer

    Function SetScreen(Optional ByVal bln As Boolean = True) As Integer
        SetScreen = SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, IIf(bln, ScreenOn, ScreenOff))
    End Function
Put the above in your code then you can use this
Code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SetScreen(False)
    End Sub
to call the function.


* - DexHacker - Feb 27, 2011

You could use your code after a 4 second delay of running this code
https://hackforums.net/showthread.php?tid=422248