📄 inputbox.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Library.Class
{
/// <summary>
/// InputBox 的摘要说明。
/// </summary>
public class InputBox : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtData;
private System.Windows.Forms.Label lblInfo;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public InputBox()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.txtData = new System.Windows.Forms.TextBox();
this.lblInfo = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(265, 77);
this.button1.Name = "button1";
this.button1.TabIndex = 5;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtData
//
this.txtData.Location = new System.Drawing.Point(20, 43);
this.txtData.Name = "txtData";
this.txtData.Size = new System.Drawing.Size(320, 21);
this.txtData.TabIndex = 4;
this.txtData.Text = "";
this.txtData.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtData_KeyDown);
//
// lblInfo
//
this.lblInfo.AutoSize = true;
this.lblInfo.Location = new System.Drawing.Point(20, 19);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(29, 17);
this.lblInfo.TabIndex = 3;
this.lblInfo.Text = "输入";
//
// InputBox
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(360, 118);
this.ControlBox = false;
this.Controls.Add(this.button1);
this.Controls.Add(this.txtData);
this.Controls.Add(this.lblInfo);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "InputBox";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "输入对话框";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 显示输入框
/// </summary>
/// <param name="keyInfo">显示消息</param>
/// <param name="Title">标题</param>
/// <returns></returns>
public static string ShowInputBox(string keyInfo,string Title)
{
InputBox inputbox = new InputBox();
inputbox.Text=Title;
if(keyInfo.Trim() != string.Empty)
inputbox.lblInfo.Text = keyInfo;
inputbox.ShowDialog();
return inputbox.txtData.Text;
}
/// <summary>
/// TextBox键盘事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -