TextBox控件的使用,MaskedTextBox控件的使用
来源:互联网 发布:软件检测工程师 编辑:程序博客网 时间:2024/06/05 19:58
1、TextBox控件的使用
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Text.RegularExpressions;namespace TextBox控件的使用{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void buttonOK_Click(object sender, EventArgs e) { string msg; msg = "用户名:" + this.textBoxName.Text + Environment.NewLine; msg += "电子邮箱:" + this.textBoxEmail.Text + Environment.NewLine; msg += "年龄:" + this.textBoxAge.Text + Environment.NewLine; this.textBoxOut.Text = msg; } private void buttonCancel_Click(object sender, EventArgs e) { Application.Exit(); } private void buttonHelp_Click(object sender, EventArgs e) { string msg; msg = "在“用户名”文本框中输入您的姓名" + Environment.NewLine; msg += "在“电子邮箱”文本框中输入您的电子邮件地址,注意使用正确的格式" + Environment.NewLine; msg += "在“年龄”文本框中输入您的年龄"; this.textBoxOut.Text = msg; } private void ValidateOK() { if (this.textBoxAge.Tag == "1" && this.textBoxName.Tag == "1" && this.textBoxEmail.Tag == "1") this.buttonOK.Enabled = true; } private void textBoxEmail_Validating(object sender, CancelEventArgs e) { TextBox tb = (TextBox)sender; Regex re = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); if (tb.Text == "" || !re.Match(tb.Text).Success) { tb.Tag = "0"; tb.BackColor = Color.FromArgb(255, 128, 128); } else { tb.Tag = "1"; tb.BackColor = SystemColors.Window; } this.ValidateOK(); } private void textBoxAge_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != 8) { //如果输入键不是0-9之间的数字表示无效 e.Handled = true; } } private void textBoxEmpty_Validating(object sender, CancelEventArgs e) { TextBox tb = (TextBox)sender; if (tb.Text == "") { tb.BackColor = Color.FromArgb(255, 128, 128); tb.Tag = "0"; } else { tb.Tag = "1"; tb.BackColor = SystemColors.Window; } this.ValidateOK(); } private void textBox_TextChanged(object sender, EventArgs e) { TextBox tb = (TextBox)sender; Regex re = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); if (tb.Text == "" && tb != this.textBoxEmail) { tb.Tag = "0"; tb.BackColor = Color.FromArgb(255, 128, 128); } else if (tb == this.textBoxEmail && tb.Text != "" && !re.Match(this.textBoxEmail.Text).Success) { tb.Tag = "0"; tb.BackColor = Color.FromArgb(255, 128, 128); } else { tb.Tag = "1"; tb.BackColor = SystemColors.Window; } this.ValidateOK(); } }}
2、MaskedTextBox控件的使用
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace MaskedTextBox控件的使用{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void buttonOK_Click(object sender, EventArgs e) { string msg; msg = "用户名:" + this.textBox1.Text + Environment.NewLine; msg += "出生日期:" + this.maskedTextBox1.Text + Environment.NewLine; msg += "身份证号:" + this.maskedTextBox2.Text + Environment.NewLine; msg += "邮政编码:" + this.maskedTextBox3.Text + Environment.NewLine; this.textBox2.Text = msg; } private void buttonCancel_Click(object sender, EventArgs e) { Application.Exit(); } private void MaskedTextBox_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) { this.statusStrip1.Items[0].Text = "只能输入数字!"; } private void maskedTextBox_KeyDown(object sender, KeyEventArgs e) { this.statusStrip1.Items[0].Text = ""; } private void textBox1_Leave(object sender, EventArgs e) { if (this.textBox1.Text == "") { this.statusStrip1.Items[0].Text = "用户名不能为空白"; this.textBox1.Focus(); } } }}
- TextBox控件的使用,MaskedTextBox控件的使用
- maskedtextbox控件的使用
- textbox控件的使用
- silverlight中TextBox控件的使用
- MaskedTextBox 控件
- 使用AJAX的方法将TextBox控件和Calendar控件结合使用,点击TextBox后弹出Calendar控件
- 使用正则表达式进行数据有效性校验的TextBox控件
- asp.net学习之textbox控件使用的小例子
- textBox控件的一点
- textBox控件的一点
- textBox控件的一点
- MaskedTextBox 窗体控件中Mask属性的掩码元素
- MaskedTextBox控件 Mask属性
- MaskedTextBox控件学习
- MaskedTextBox 控件自定义快捷键
- CListCtrl控件控件的使用
- TextBox和Calendar结合使用(使用ajax控件的简单方法)
- DropDownList控件 与TextBox控件的组合
- 深刻了解OPENCV
- 像素和厘米的关系,设计打印预览和实际打印的关系
- Android Button Example-onClickListener-Intent
- mybatis 与 ehcache 整合
- VSS的配置和使用
- TextBox控件的使用,MaskedTextBox控件的使用
- 基于weibopy sina接口数据的设想与实现
- List、Set
- IOS开发之把 JSON 数据转化成 Arrays 或者 Dictionaries
- 黑马程序员--01 c#基础知识
- android ListView
- MDI窗体应用程序
- 在 Codeigniter(CI)中引入外部的JS与CSS的配置及使用
- 系统调用