-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputDialog.cs
More file actions
55 lines (47 loc) · 1.98 KB
/
Copy pathInputDialog.cs
File metadata and controls
55 lines (47 loc) · 1.98 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
using System.Drawing;
using System.Windows.Forms;
namespace GenericForms
{
public class InputDialog
{
public static DialogResult ShowInputDialog(ref string input, string formTitle, string formPrompt)
{
Size size = new Size(400, 0);
Form inputBox = new Form();
inputBox.FormBorderStyle = FormBorderStyle.FixedDialog;
inputBox.ClientSize = size;
inputBox.Text = formTitle;
inputBox.AutoSize = true;
Label label = new Label();
label.MaximumSize = new Size(size.Width, 0);
label.AutoSize = true;
label.Location = new Point(10, 10);
label.Text = formPrompt;
inputBox.Controls.Add(label);
TextBox textBox = new TextBox();
textBox.Size = new Size(size.Width - 20, 0);
textBox.Location = new Point(10, label.Size.Height + 20);
textBox.Text = input;
inputBox.Controls.Add(textBox);
Button okButton = new Button();
okButton.DialogResult = DialogResult.OK;
okButton.Name = "okButton";
okButton.Size = new Size(75, 23);
okButton.Text = "&OK";
okButton.Location = new Point(size.Width - 80 - 90, label.Size.Height + textBox.Size.Height + 30);
inputBox.Controls.Add(okButton);
Button cancelButton = new Button();
cancelButton.DialogResult = DialogResult.Cancel;
cancelButton.Name = "cancelButton";
cancelButton.Size = new Size(75, 23);
cancelButton.Text = "&Cancel";
cancelButton.Location = new Point(size.Width - 85, label.Size.Height + textBox.Size.Height + 30);
inputBox.Controls.Add(cancelButton);
inputBox.AcceptButton = okButton;
inputBox.CancelButton = cancelButton;
DialogResult result = inputBox.ShowDialog();
input = textBox.Text;
return result;
}
}
}