[汇编]maskedTextBox实例收集
maskedTextBox实例收集
?????主程序文件完整程序代码????? using System;
using System.Collections.Generic; using System.Windows.Forms; namespace _8_18
{
static class Program
{
///
本教程来自
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMaskedTextBox()); }
}
}
?????frmMaskedTextBox窗体设计文件完整程序代码网站源代
码?????
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _8_18
{
public partial class frmMaskedTextBox : Form {
public frmMaskedTextBox()
{
InitializeComponent();
}
Binding currentBinding, phoneBinding; DataSet employeesTable = new DataSet(); SqlConnection sc;
SqlDataAdapter dataConnect;
private void frmMaskedTextBox_Load(object sender, EventArgs
e)
{
//maskedTextBox1.Mask = "00/00/0000"; maskedTextBox1.ValidatingType = typeof(System.DateTime);
}
private void maskedTextBox1_MaskInputRejected(object sender,
MaskInputRejectedEventArgs e)
{
toolTip1.ToolTipTitle = "日期"; toolTip1.Show("你输入的类型不证确请输入一个日期", maskedTextBox1, 5000);
}
private void maskedTextBox1_TypeValidationCompleted(object
sender, TypeValidationEventArgs e) {
}
}
}
?????frmMaskedTextBox窗体代码文件完整程序代码?????
namespace _8_18
{
partial class frmMaskedTextBox
{
///
本教程来自
/// 必需的设计器变量。
///
private System.ComponentModel.IContainer components = null;
///
/// 清理所有正在使用的资源。
///
///
如果应释放托管资源,为 true;否则为 false。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
///
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.maskedTextBox1 = new
System.Windows.Forms.MaskedTextBox();
this.toolTip1 = new
System.Windows.Forms.ToolTip(this.components);
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// maskedTextBox1
//
this.maskedTextBox1.Location = new System.Drawing.Point(34, 56);
this.maskedTextBox1.Name = "maskedTextBox1";
this.maskedTextBox1.Size = new System.Drawing.Size(111, 21);
this.maskedTextBox1.TabIndex = 0;
this.maskedTextBox1.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.maskedTextBox1_MaskInputRejected);
this.maskedTextBox1.TypeValidationCompleted += new System.Windows.Forms.TypeValidationEventHandler(this.maskedTextBox1_TypeValidationCompleted);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(32, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(113, 12);
this.label1.TabIndex = 1;
this.label1.Text = "输入日期yyyy-mm-dd";
//
// button1
//
this.button1.Location = new System.Drawing.Point(34, 83);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(111, 23);
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.UseVisualStyleBackColor = true;
//
// frmMaskedTextBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(191, 112);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.maskedTextBox1); this.Name = "frmMaskedTextBox";
this.Text = "frmMaskedTextBox";
this.Load += new
System.EventHandler(this.frmMaskedTextBox_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MaskedTextBox maskedTextBox1;
private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; }
}
示例
MaskInputRejected事件
本示例通过在MaskInputRejected事件下编写代码,来判断用户输入的数据是否正确。示例运行结果如图2所示。网站源代码
图2 MaskInputRejected事件的使用
程序主要代码如下:
private void maskedTextBox1_MaskInputRejected(object sender,
MaskInputRejectedEventArgs e)
{
toolTip1.ToolTipTitle = "日期";
toolTip1.Show("你输入的类型不证确请输入一个日期", maskedTextBox1, 5000);
}
完整程序代码如下:
?????主程序文件完整程序代码????? using System;
using System.Collections.Generic; using System.Windows.Forms;
namespace _8_18
{
static class Program
{
///
本教程来自
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMaskedTextBox()); }
}
}
?????frmMaskedTextBox窗体设计文件完整程序代码
?????
using System;
using System.Collections.Generic; using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _8_18
{
public partial class frmMaskedTextBox : Form {
public frmMaskedTextBox()
{
InitializeComponent();
}
Binding currentBinding, phoneBinding; DataSet employeesTable = new DataSet(); SqlConnection sc;
SqlDataAdapter dataConnect;
private void frmMaskedTextBox_Load(object sender, EventArgs
e)
{
//maskedTextBox1.Mask = "00/00/0000"; maskedTextBox1.ValidatingType = typeof(System.DateTime);
}
private void maskedTextBox1_MaskInputRejected(object sender,
MaskInputRejectedEventArgs e)
{
toolTip1.ToolTipTitle = "日期"; toolTip1.Show("你输入的类型不证确请输入一个日期", maskedTextBox1, 5000);(
?????frmMaskedTextBox窗体代码文件完整程序代码
?????
namespace _8_18
{
partial class frmMaskedTextBox {
///
/// 必需的设计器变量。
///
private System.ComponentModel.IContainer components = null;
///
/// 清理所有正在使用的资源。 ///
///
如果应释放托管资源,为 true;否
则为 false。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码 ///
/// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。网站源代码
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.maskedTextBox1 = new
System.Windows.Forms.MaskedTextBox();
this.toolTip1 = new
System.Windows.Forms.ToolTip(this.components);
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// maskedTextBox1
//
this.maskedTextBox1.Location = new System.Drawing.Point(34, 56);
this.maskedTextBox1.Name = "maskedTextBox1";
this.maskedTextBox1.Size = new System.Drawing.Size(111, 21);
this.maskedTextBox1.TabIndex = 0;
this.maskedTextBox1.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.maskedTextBox1_MaskInputRejected);
this.maskedTextBox1.TypeValidationCompleted += new System.Windows.Forms.TypeValidationEventHandler(this.maskedTextBox1_TypeValidationCompleted);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(32, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(113, 12);
this.label1.TabIndex = 1;
this.label1.Text = "输入日期yyyy-mm-dd";
//
// button1
//
this.button1.Location = new System.Drawing.Point(34, 83);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(111, 23);
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.UseVisualStyleBackColor = true;
//
// frmMaskedTextBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(191, 112);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.maskedTextBox1);
this.Name = "frmMaskedTextBox";
this.Text = "frmMaskedTextBox";
this.Load += new
System.EventHandler(this.frmMaskedTextBox_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MaskedTextBox maskedTextBox1;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
}
}