-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathHotKeyControl.cs
More file actions
74 lines (66 loc) · 1.85 KB
/
HotKeyControl.cs
File metadata and controls
74 lines (66 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
public partial class HotKeyControl :
UserControl
{
public HotKeyControl()
{
InitializeComponent();
keyCombo.Items.AddRange(GetAlphabet().ToArray());
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public HotKey? HotKey
{
get
{
if (!hotKeyEnabled.Checked)
{
return null;
}
return new()
{
Shift = shift.Checked,
Control = control.Checked,
Alt = alt.Checked,
Key = (string) keyCombo.SelectedItem!
};
}
set
{
if (value == null)
{
return;
}
hotKeyEnabled.Checked = true;
keyCombo.SelectedItem = value.Key;
shift.Checked = value.Shift;
control.Checked = value.Control;
alt.Checked = value.Alt;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string Label
{
get => hotKeyEnabled.Text;
set => hotKeyEnabled.Text = value;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string? Help
{
get => (string?) helpLabel.Text;
set => helpLabel.Text = value;
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
var padding = hotKey.Padding;
helpLabel.MaximumSize = new(hotKey.Width - (padding.Left + padding.Right + 10), 0);
}
static IEnumerable<string> GetAlphabet()
{
for (var c = 'A'; c <= 'Z'; c++)
{
yield return c.ToString();
}
}
void hotKeyEnabled_CheckedChanged(object sender, EventArgs e) =>
keysSelectionPanel.Enabled = hotKeyEnabled.Checked;
}