c# WinForm 文本输入对话框

这种功能为什么不向MessageBox一样自带,还得自己写~~



代码:

public InputBox(string label)
{
    InitializeComponent();
    label1.Text = label;
}

public InputBox(string label, string title)
{
    InitializeComponent();
    label1.Text = label;
    this.Text = title;
}

//取消
private void button2_Click(object sender, EventArgs e)
{
    this.DialogResult = DialogResult.Cancel;
    this.Close();
}
//确定
private void button1_Click(object sender, EventArgs e)
{
    this.DialogResult = DialogResult.OK;
    Value = textBox1.Text;
    this.Close();
}private void InputBox_Load(object sender, EventArgs e)
{
    textBox1.Focus();
    textBox1.Text = Value;
}

public string Value { get; set; }

窗体设计:

注意修改窗口属性:

this.AcceptButton = this.button1;
this.CancelButton = this.button2;
this.FormBorderStyle = FormBorderStyle.FixedDialog;


用法:

InputBox inp = new InputBox("Lable内的值");
DialogResult dr = inp.ShowDialog();
if (dr == DialogResult.OK && inp.Value.Length > 0)
{
    操作代码
}
inp.Dispose();
时间: 2024-08-15 01:09:10

c# WinForm 文本输入对话框的相关文章

prompt 方法显示输入对话框

prompt 方法显示输入对话框 原理: prompt() 方法用于与用户交互,提示用户输入信息的对话框. prompt(str1,str2);此方法包含两个属性: str1:用于提示用户输入的信息. str2:用于用户输入文本信息. 该方法返回值:返回用户输入的文本信息. 简单实例: <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</tit

iOS9使用提示框进行文本输入的正确实现方式

我在之前写过一篇博客<iOS9使用提示框的正确实现方式>,主要讲了如何使用UIAlertController替换UIAlertView进行提示框的实现.今天我们将会来实现一下在提示框中如何进行文本输入.该功能可以让用户进行密码确认等功能. 实现代码如下: #import "SecondViewController.h" #import "AppDelegate.h" @interface SecondViewController () @end @imp

设置警告框样式为带有两个文本输入的警告框,用于收集用户收货地址和联系电话。并选择合适的代理方法,当警告框上的两输入框有一个为空时限制“购买”按钮点击。

收集购物信息  iOS项目 倒计时:588 步骤 /.panel-heading 项目需求 设置警告框样式为带有两个文本输入的警告框,用于收集用户收货地址和联系电话.并选择合适的代理方法,当警告框上的两输入框有一个为空时限制“购买”按钮点击. #import "TableViewController.h" @interface TableViewController ()<UIAlertViewDelegate> @property (nonatomic, strong)

Cocos2d-x 3.4 之 文本输入之 EditBox

***************************************转载请注明出处:http://blog.csdn.net/lttree******************************************** 上一篇,说了 文本输入的 CCTextFieldTTF, 这次继续来弄文本输入,EditBox 做完CCTextFieldTTF以后,马上就搞这个EditBox了, 但是,改动有些多,而且好多BUG啊,网上资料也不多,整的我焦头烂额... 先发一些基础的,具体其

【cocos2d-x学习笔记】文本输入、菜单、内存管理、定时器

文本输入 CCTextFiledTTF CCTextFiledTTF *textEdit = CCTextFiledTTF::textFiledWithPlaceHolder("input", "Arial", 33); textEdit->atchWithIME();      弹出软键盘 textEdit->setSecureTextEntry(true);  密码格式输入 CCEditBox CCScale9Sprite *bg = CCScale

WinForm MessageBox 提示对话框

public class MessageUtil { /// <summary> /// 显示一般的提示信息 /// </summary> /// <param name="message">提示信息</param> public static DialogResult ShowTips(string message) { return MessageBox.Show(message, "提示信息",MessageBo

文本输入

1.隐藏文本框的键盘,Return类型设为UIReturnKeyDone,代理方法textD\FieldShouldReturn,视图控制器可以强令键盘留在键盘上,重写disablesAutomaticKeyBoardDismissal 2.UITextInputTraints协议中的属性:autocapitalizationType文本的自动大写,autocorrectionType自动修正,spellCheckingType是否进行拼写检查,keyboardAppearance键盘风格,ke

Java Swing界面编程(17)---单行文本输入组件:JTextField

package com.beyole.util; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class test15 { public static void main(String[] args) { JFrame frame = new JFrame("Crystal");// 实例化窗

Java Swing界面编程(18)---单行文本输入组件:JTextField

以下的程序与上一例有一点区别,仔细对比不难发现其中的不同之处. package com.beyole.util; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class test17 { public static void main(String[] args) { JFrame frame = new JFrame("Crystal"); JT