代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
输入提示框
作者:
codeeer
/ 发布于
2014/7/17
/
517
///Demo string DemoString = InputBox.ShowInputBox("新方案", "请输入新方案名称:", "方案1", True); Console.WriteLine(DemoString); ///类似于VB的MsgBox,不过更强大一点^^ /// <summary> /// 信息输入框 /// /// Demo: /// string DemoString = iDLL.Forms.InputBox.ShowInputBox("新方案", "请输入新方案名称:", "方案1", True); /// Console.WriteLine(DemoString); /// </summary> public class InputBox : System.Windows.Forms.Form { private TextBox txtData; private System.Windows.Forms.Label lblInfo; private Button button1; private Button button2; private System.ComponentModel.Container components = null; private InputBox(string DefaultInput, bool UsePasswordForm) { InitializeComponent(DefaultInput, UsePasswordForm); } protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } private void InitializeComponent(string DefaultInput, bool UsePasswordForm) { this.txtData = new System.Windows.Forms.TextBox(); this.lblInfo = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtData // this.txtData.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.txtData.Location = new System.Drawing.Point(19, 76); this.txtData.Name = "txtData"; this.txtData.Size = new System.Drawing.Size(400, 21); this.txtData.TabIndex = 0; if (UsePasswordForm) { this.txtData.PasswordChar = '*'; } if (DefaultInput != null) { this.txtData.Text = DefaultInput; } this.txtData.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtData_KeyDown); // // lblInfo // this.lblInfo.BackColor = System.Drawing.SystemColors.ButtonFace; 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, 9); this.lblInfo.Name = "lblInfo"; this.lblInfo.Size = new System.Drawing.Size(317, 56); this.lblInfo.TabIndex = 1; // // button1 // this.button1.DialogResult = System.Windows.Forms.DialogResult.OK; this.button1.Location = new System.Drawing.Point(352, 9); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(67, 27); this.button1.TabIndex = 2; this.button1.Text = "确认"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.button2.Location = new System.Drawing.Point(352, 38); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(67, 27); this.button2.TabIndex = 3; this.button2.Text = "取消"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // InputBox // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(431, 111); this.ControlBox = false; this.Controls.Add(this.button2); this.Controls.Add(this.button1); 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(); } } //显示InputBox public static string ShowInputBox(string Title, string keyInfo, string DefaultInput = null, bool UsePasswordForm = false) { InputBox inputbox = new InputBox(DefaultInput, UsePasswordForm); inputbox.Text = Title; inputbox.TopMost = true; if (keyInfo.Trim() != string.Empty) { inputbox.lblInfo.Text = keyInfo; } inputbox.ShowDialog(); return inputbox.txtData.Text; } private void button2_Click(object sender, EventArgs e) { txtData.Text = ""; } private void button1_Click(object sender, EventArgs e) { } }
试试其它关键字
提示框
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
codeeer
贡献的其它代码
(
23
)
.
绑定仅程序内有效的热键
.
以管理员身份运行
.
关机重启注销锁定
.
关闭窗体
.
生成密码字典
.
对Listview点击列标题自动排序
.
延时函数
.
输入提示框
.
检测是否已经安装Winrar
.
多线程作业
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3