我有一个ScreenLocker winform应用程序.它是全屏和透明的.当用户按下时它会解锁屏幕Ctrl+Alt+Shift+P.
但我希望它更有活力.我想让用户在配置文件中设置自己的密码.
例如,他设置了密码mypass.我的问题是 - 如何跟踪他是否在该表单上键入"mypass"?
我不想在表单上有任何文本框或按钮.请帮忙.
这是我目前的代码 -
public frmMain()
{
InitializeComponent();
this.KeyPreview = true;
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
this.ShowInTaskbar = false;
double OpacityValue = 4.0 / 100;
this.Opacity = OpacityValue;
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.P && e.Modifiers == (Keys.Control | Keys.Shift | Keys.Alt))
{
this.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
您可以将键入的字母存储在变量中,然后在 Enter keydown 事件中检查它。这是工作样本-
public partial class Form1 : Form
{
String pass = String.Empty;
public Form1()
{
InitializeComponent();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
string value = e.KeyChar.ToString();
pass += value;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter)
{
//Now check the password with your config file.
//You may have to reset the variable if the pass does not match with the config.
}
}
}
Run Code Online (Sandbox Code Playgroud)