Created
October 9, 2024 12:52
-
-
Save verdipratama/59ee6bd0a39c67609a6aaa7f797207ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
using System.Runtime.InteropServices; | |
namespace LockScreenApp | |
{ | |
public partial class Form1 : Form | |
{ | |
[DllImport("user32.dll")] | |
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); | |
const int SW_HIDE = 0; | |
const int SW_SHOW = 5; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
// Set form ke mode full screen dan selalu di atas | |
this.WindowState = FormWindowState.Maximized; | |
this.FormBorderStyle = FormBorderStyle.None; | |
this.TopMost = true; | |
// Sembunyikan taskbar | |
ShowWindow(this.Handle, SW_HIDE); | |
// Tangkap event ketika pengguna mencoba mematikan komputer | |
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; | |
} | |
private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) | |
{ | |
if (e.Mode == PowerModes.Suspend) | |
{ | |
// Cegah komputer masuk ke mode tidur | |
e.Cancel = true; | |
} | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
// Tombol logout, kembalikan kontrol ke pengguna | |
this.Close(); | |
ShowWindow(this.Handle, SW_SHOW); // Tampilkan kembali taskbar | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment