一个c#的输入框函数
2017-01-26 10:15
281 查看
private static string InputBox(string Caption, string Hint, string Default) { Form InputForm = new Form(); InputForm.MinimizeBox = false; InputForm.MaximizeBox = false; InputForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; InputForm.StartPosition = FormStartPosition.CenterScreen; InputForm.Width = 220; InputForm.Height = 150; InputForm.Text = Caption; Label lbl = new Label(); lbl.Text = Hint; lbl.Left = 10; lbl.Top = 20; lbl.Parent = InputForm; lbl.AutoSize = true; TextBox tb = new TextBox(); tb.Left = 30; tb.Top = 45; tb.Width = 160; tb.Parent = InputForm; tb.Text = Default; tb.SelectAll(); Button btnok = new Button(); btnok.Left = 30; btnok.Top = 80; btnok.Parent = InputForm; btnok.Text = "确定"; InputForm.AcceptButton = btnok;//回车响应 btnok.DialogResult = DialogResult.OK; Button btncancal = new Button(); btncancal.Left = 120; btncancal.Top = 80; btncancal.Parent = InputForm; btncancal.Text = "取消"; btncancal.DialogResult = DialogResult.Cancel; try { if (InputForm.ShowDialog() == DialogResult.OK) { return tb.Text; } else { return null; } } finally { InputForm.Dispose(); } }
相关文章推荐
- C#中两个Form窗口之间的传值(父->子)(子->父)
- c#datagridview
- c#编码转换
- C#嵌入dll到资源释放的问题
- C#多线程同步事件及等待句柄AutoResetEvent 和 ManualResetEvent
- C#属性-索引器-里氏替换-多态-虚方法-抽象-接口-泛型-
- C#委托
- C#时间戳转时间-时间转时间戳
- C#字符串操作 取文本左边 取文本右边 取文本中间 取文本中间到List集合 指定文本倒序
- mstsc 远程序桌面登录的 c#开发
- c#如何实现一个线程暂停,等待用户输入文本后继续运行?
- 4000 C#的引用类型和值类型
- C#常用命令库(备用)
- C#90课的主要内容
- C#之对象数组排序
- c#字符串切割split使用方法
- rest api+C#
- c#不同数组之间的转换【转载,消化自动删除】
- C# 事件
- C# 操作符??和?: