-
Notifications
You must be signed in to change notification settings - Fork 3
/
GetStringDlg.cs
90 lines (77 loc) · 2.22 KB
/
GetStringDlg.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace P4EXP
{
public partial class GetStringDlg : AutoSizeForm
{
public GetStringDlg(string Caption, string prompt, string DefaultValue)
{
PreferenceKey = "GetStringDlg";
InitializeComponent();
this.Text = Caption;
PromptLbl.Text = prompt;
if (DefaultValue != null)
{
ValueTB.Text = DefaultValue;
}
}
private GetStringDlg() {}
public string Value { get { return ValueTB.Text; } }
public static string Show(string Caption, string prompt, string DefaultValue)
{
return Show(Caption, prompt, DefaultValue, false);
}
public static string Show(string Caption, string prompt, string DefaultValue, bool isPassword)
{
GetStringDlg dlg = new GetStringDlg(Caption, prompt, DefaultValue);
dlg.FormBorderStyle = FormBorderStyle.FixedSingle;
dlg.AutoSize = true;
dlg.gridLayoutPanel1.AutoSize = true;
dlg.PromptLbl.Dock = DockStyle.Fill;
dlg.ValueTB.UseSystemPasswordChar = isPassword;
if (isPassword)
{
dlg.ShowIcon = true;
dlg.TopMost = true;
}
if (dlg.ShowDialog() != DialogResult.Cancel)
{
if (dlg.DialogResult == DialogResult.OK)
{
return dlg.Value;
}
}
return null;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (ValueTB.UseSystemPasswordChar)
{
//getting a password, so center on the VS Window
StartPosition = FormStartPosition.CenterParent;
}
}
private void ValueTB_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
newOKBtn.PerformClick();
}
private void GetStringDlg_Load(object sender, EventArgs e)
{
if ((ValueTB.UseSystemPasswordChar) && (StartPosition == FormStartPosition.CenterParent))
{
// if opening in the default location, move it uup the screen so it can't
// end up behind the VS initializing progress box, which is also always on top.
StartPosition = FormStartPosition.Manual;
Top -= Top / 2;
}
}
}
}