Skip to content

Commit 37dd5a2

Browse files
committed
密码框弹出方式支持配置
1 parent 363bd88 commit 37dd5a2

File tree

9 files changed

+232
-34
lines changed

9 files changed

+232
-34
lines changed

src/AppConfigInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ internal class AppConfigInfo
5454
/// 自动隐藏密码框
5555
/// </summary>
5656
public bool IsHidePasswordWindow { get; set; } = true;
57+
58+
/// <summary>
59+
/// 密码框激活方式
60+
/// </summary>
61+
public PasswordBoxActiveMethodEnum PasswordBoxActiveMethod { get; set; } = PasswordBoxActiveMethodEnum.KeyboardDown | PasswordBoxActiveMethodEnum.MouseDown;
5762
}

src/FmLockScreenBlank.cs

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Data;
5-
using System.Drawing;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
92
using System.Windows.Forms;
103

114
namespace ComputerLock
@@ -14,6 +7,8 @@ public partial class FmLockScreenBlank : Form
147
{
158
private bool _isUnlock = false;
169
public event EventHandler<EventArgs>? OnDeviceInput;
10+
private int _unlockAreaHeigh = 70;
11+
private int _unlockAreaWidth = 160;
1712
public FmLockScreenBlank()
1813
{
1914
InitializeComponent();
@@ -32,14 +27,71 @@ protected override void OnPaintBackground(PaintEventArgs e) { /* Ignore */ }
3227

3328
private void FmLockScreenBlank_KeyDown(object sender, KeyEventArgs e)
3429
{
30+
if ((AppBase.Config.PasswordBoxActiveMethod & PasswordBoxActiveMethodEnum.KeyboardDown) != PasswordBoxActiveMethodEnum.KeyboardDown)
31+
{
32+
return;
33+
}
3534
OnDeviceInput?.Invoke(this, EventArgs.Empty);
3635
}
3736

3837
private void FmLockScreenBlank_MouseClick(object sender, MouseEventArgs e)
3938
{
4039
//这里只响应左键
4140
//因为为了实现禁用 Windows 锁屏,会定时点击鼠标右键
42-
if (e.Button == MouseButtons.Left)
41+
if (e.Button != MouseButtons.Left)
42+
{
43+
return;
44+
}
45+
if ((AppBase.Config.PasswordBoxActiveMethod & PasswordBoxActiveMethodEnum.MouseDown) != PasswordBoxActiveMethodEnum.MouseDown)
46+
{
47+
return;
48+
}
49+
50+
int xMin;
51+
int xMax;
52+
int yMin;
53+
int yMax;
54+
switch (AppBase.Config.PasswordInputLocation)
55+
{
56+
case ScreenLocationEnum.Center:
57+
xMin = this.Width / 2 - _unlockAreaWidth / 2;
58+
xMax = this.Width / 2 + _unlockAreaWidth / 2;
59+
yMin = this.Height / 2 - _unlockAreaHeigh / 2;
60+
yMax = this.Height / 2 + _unlockAreaHeigh / 2;
61+
break;
62+
case ScreenLocationEnum.TopLeft:
63+
xMin = 0;
64+
xMax = _unlockAreaWidth;
65+
yMin = 0;
66+
yMax = _unlockAreaHeigh;
67+
break;
68+
case ScreenLocationEnum.TopRight:
69+
xMin = this.Width - _unlockAreaWidth;
70+
xMax = this.Width;
71+
yMin = 0;
72+
yMax = _unlockAreaHeigh;
73+
break;
74+
case ScreenLocationEnum.BottomLeft:
75+
xMin = 0;
76+
xMax = _unlockAreaWidth;
77+
yMin = this.Height - _unlockAreaHeigh;
78+
yMax = this.Height;
79+
break;
80+
case ScreenLocationEnum.BottomRight:
81+
xMin = this.Width - _unlockAreaWidth;
82+
xMax = this.Width;
83+
yMin = this.Height - _unlockAreaHeigh;
84+
yMax = this.Height;
85+
break;
86+
default:
87+
xMin = this.Width / 2 - _unlockAreaWidth / 2;
88+
xMax = this.Width / 2 + _unlockAreaWidth / 2;
89+
yMin = this.Height / 2 - _unlockAreaHeigh / 2;
90+
yMax = this.Height / 2 + _unlockAreaHeigh / 2;
91+
break;
92+
}
93+
94+
if (e.X >= xMin && e.X <= xMax && e.Y >= yMin && e.Y <= yMax)
4395
{
4496
OnDeviceInput?.Invoke(this, EventArgs.Empty);
4597
}

src/FmMain.Designer.cs

Lines changed: 47 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/FmMain.cs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ private void AppConfigToUi()
8787
ChkIsDisableWindowsLock.Checked = AppBase.Config.IsDisableWindowsLock;
8888
ChkIsAutoCheckUpdate.Checked = AppBase.Config.IsAutoCheckUpdate;
8989
ChkIsHidePasswordWindow.Checked = AppBase.Config.IsHidePasswordWindow;
90+
91+
var KeyboardDownChecked = (AppBase.Config.PasswordBoxActiveMethod & PasswordBoxActiveMethodEnum.KeyboardDown) == PasswordBoxActiveMethodEnum.KeyboardDown;
92+
var mouseDownChecked = (AppBase.Config.PasswordBoxActiveMethod & PasswordBoxActiveMethodEnum.MouseDown) == PasswordBoxActiveMethodEnum.MouseDown;
93+
ChkKeyboardDownActivePwd.Checked = KeyboardDownChecked;
94+
ChkMouseDownActivePwd.Checked = mouseDownChecked;
95+
9096
UpdateAutostartUi();
9197
UpdateLangLocation();
9298
UpdatePasswordInputLocation();
@@ -284,6 +290,55 @@ private void ChkIsHidePasswordWindow_CheckedChanged(object sender, EventArgs e)
284290
AppBase.Config.IsHidePasswordWindow = ChkIsHidePasswordWindow.Checked;
285291
SaveAppConfig();
286292
}
293+
294+
private void ChkKeyboardDownActivePwd_CheckedChanged(object sender, EventArgs e)
295+
{
296+
CheckBox checkBox = (CheckBox)sender;
297+
bool isChecked = checkBox.Checked;
298+
bool isMouseDownChecked = ChkMouseDownActivePwd.Checked;
299+
if (isChecked == false)
300+
{
301+
if (isMouseDownChecked == false)
302+
{
303+
checkBox.Checked = !isChecked;
304+
MessageBoxUtils.ShowInfo(_resources.GetString("ActiveMethodEmpty", CultureInfo.CurrentCulture));
305+
return;
306+
}
307+
}
308+
SavePasswordBoxActiveMethod(isMouseDownChecked, isChecked);
309+
}
310+
311+
private void ChkMouseDownActivePwd_CheckedChanged(object sender, EventArgs e)
312+
{
313+
CheckBox checkBox = (CheckBox)sender;
314+
bool isChecked = checkBox.Checked;
315+
bool isKeyboardDownChecked = ChkKeyboardDownActivePwd.Checked;
316+
if (isChecked == false)
317+
{
318+
if (isKeyboardDownChecked == false)
319+
{
320+
checkBox.Checked = !isChecked;
321+
MessageBoxUtils.ShowInfo(_resources.GetString("ActiveMethodEmpty", CultureInfo.CurrentCulture));
322+
return;
323+
}
324+
}
325+
SavePasswordBoxActiveMethod(isChecked, isKeyboardDownChecked);
326+
}
327+
328+
private void SavePasswordBoxActiveMethod(bool isMouseDownChecked, bool isKeyboardDownChecked)
329+
{
330+
AppBase.Config.PasswordBoxActiveMethod = 0;
331+
if (isMouseDownChecked)
332+
{
333+
AppBase.Config.PasswordBoxActiveMethod = AppBase.Config.PasswordBoxActiveMethod | PasswordBoxActiveMethodEnum.MouseDown;
334+
}
335+
if (isKeyboardDownChecked)
336+
{
337+
AppBase.Config.PasswordBoxActiveMethod = AppBase.Config.PasswordBoxActiveMethod | PasswordBoxActiveMethodEnum.KeyboardDown;
338+
}
339+
SaveAppConfig();
340+
}
341+
287342
private void BtnPassword_Click(object sender, EventArgs e)
288343
{
289344
var fmPassword = new FmPassword();
@@ -403,10 +458,6 @@ private void SetControlLanguage(Control control)
403458
if (childControl.HasChildren)
404459
{
405460
SetControlLanguage(childControl);
406-
}
407-
if (childControl.Name == "Tray")
408-
{
409-
410461
}
411462
string? value = _resources.GetString(childControl.Name, CultureInfo.CurrentCulture);
412463
if (value == null)

src/PasswordBoxActiveMethodEnum.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace ComputerLock;
4+
[Flags]
5+
internal enum PasswordBoxActiveMethodEnum
6+
{
7+
KeyboardDown = 1,
8+
MouseDown = 2
9+
}

0 commit comments

Comments
 (0)