-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGooseInputForm.cs
More file actions
97 lines (80 loc) · 2.72 KB
/
Copy pathGooseInputForm.cs
File metadata and controls
97 lines (80 loc) · 2.72 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Drawing;
using System.Windows.Forms;
public class GooseInputForm : Form
{
private GooseAIConfig _cfg = GooseAIConfig.Load();
private readonly TextBox _input;
private readonly Button _ok;
private static GooseInputForm _instance;
public string UserInput => _input.Text;
private GooseInputForm(Point screenPos, string prompt)
{
FormBorderStyle = FormBorderStyle.None;
StartPosition = FormStartPosition.Manual;
BackColor = Color.White;
Padding = new Padding(10);
Location = screenPos;
var label = new Label
{
Text = prompt,
AutoSize = true,
Parent = this,
Location = new Point(Padding.Left, Padding.Top)
};
_input = new TextBox
{
Width = 200,
Parent = this,
Location = new Point(Padding.Left, label.Bottom + 5)
};
_ok = new Button
{
Text = _cfg.bubbleEnterText,
Parent = this,
Location = new Point(Padding.Left, _input.Bottom + 8),
DialogResult = DialogResult.OK
};
_ok.Click += (s, e) => Close();
_input.KeyDown += (s, e) =>
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
e.SuppressKeyPress = true;
DialogResult = DialogResult.OK;
Close();
}
};
Resize += (s, e) =>
{
int radius = 20;
var path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddArc(0, 0, radius, radius, 180, 90);
path.AddArc(Width - radius, 0, radius, radius, 270, 90);
path.AddArc(Width - radius, Height - radius, radius, radius, 0, 90);
path.AddArc(0, Height - radius, radius, radius, 90, 90);
path.CloseAllFigures();
Region = new Region(path);
};
Width = Padding.Horizontal + Math.Max(label.PreferredWidth, _input.Width);
Height = _ok.Bottom + Padding.Bottom;
}
public static string ShowAt(Point screenPos, string prompt)
{
if (_instance != null)
{
_instance.BringToFront();
_instance.Focus();
return string.Empty;
}
_instance = new GooseInputForm(screenPos, prompt);
_instance.Shown += (s, e) => _instance._input.Focus();
string input = string.Empty;
if (_instance.ShowDialog() == DialogResult.OK)
input = _instance.UserInput;
_instance.Dispose();
_instance = null;
return input;
}
}