This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
usb-lockdown/USB Lockdown/lockScreen.cs

50 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace USB_Lockdown
{
public partial class lockScreen : Form
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
public lockScreen()
{
InitializeComponent();
KeyboardLock.enable();
setupWindow();
}
private void setupWindow()
{
this.StartPosition = FormStartPosition.CenterScreen;
this.Height = SystemInformation.VirtualScreen.Height;
this.Width = SystemInformation.VirtualScreen.Width;
this.WindowState = FormWindowState.Maximized;
this.BackColor = Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
SetForegroundWindow(this.Handle);
this.ShowInTaskbar = false;
}
private void onClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; } //disables alt+F4
}
private void keepForeground(object sender, EventArgs e) { SetForegroundWindow(this.Handle); }
}
}