-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputBox.cs
More file actions
109 lines (97 loc) · 3.75 KB
/
Copy pathInputBox.cs
File metadata and controls
109 lines (97 loc) · 3.75 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
98
99
100
101
102
103
104
105
106
107
108
109
using System.Windows.Forms;
namespace ModbusSample
{
/// <summary>
/// clsInputBox 的摘要说明。
/// </summary>
public class InputBox : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtData;
private System.Windows.Forms.Label lblInfo;
private System.ComponentModel.Container components = null;
private InputBox()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.txtData = new System.Windows.Forms.TextBox();
this.lblInfo = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtData
//
this.txtData.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtData.Location = new System.Drawing.Point(19, 8);
this.txtData.Name = "txtData";
this.txtData.Size = new System.Drawing.Size(317, 23);
this.txtData.TabIndex = 0;
this.txtData.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtData_KeyDown);
//
// lblInfo
//
this.lblInfo.BackColor = System.Drawing.SystemColors.Info;
this.lblInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblInfo.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblInfo.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblInfo.ForeColor = System.Drawing.Color.Gray;
this.lblInfo.Location = new System.Drawing.Point(19, 32);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(317, 16);
this.lblInfo.TabIndex = 1;
this.lblInfo.Text = "[Enter]确认 | [Esc]取消";
//
// InputBox
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(350, 48);
this.ControlBox = false;
this.Controls.Add(this.lblInfo);
this.Controls.Add(this.txtData);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "InputBox";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "InputBox";
this.ResumeLayout(false);
this.PerformLayout();
}
//对键盘进行响应
private void txtData_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.Close();
}
else if (e.KeyCode == Keys.Escape)
{
txtData.Text = string.Empty;
this.Close();
}
}
public string DefaultValue { get; set; }
//显示InputBox
public static string ShowInputBox(string title, string keyInfo = "", string defaultValue = "")
{
InputBox inputbox = new InputBox();
inputbox.Text = title;
if (keyInfo.Trim() != string.Empty)
{
inputbox.lblInfo.Text = keyInfo;
}
inputbox.DefaultValue = defaultValue;
inputbox.ShowDialog();
return inputbox.txtData.Text;
}
}
}