All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
c#写系统日志_[Asp.Net教程]
怎样使用AJAX进行WEB应用程序开发_[AJAX教程]
你必须知道的.NET之class和struct_[Asp.Net教程]
HTML初级指南〉标签属性和元素_[Html教程]
asp.net2.0中GridView控件应用实例
Asp.net数据库操作类
HTML语言剖析(十)链接标记_[Html教程]
delphi类的多态性
用PHP程序实现删除目录的三种方法实例_[PHP教程]
DataTable,DataSet与DataReader之间转换_[Asp.Net教程]
Reading number is top 10 pictures
Ashlynn Brooke a group sexy photo2
Sora aoi in China1
Is said to be a Chinese female artist fame explicit pictures before1
性感丰满身材火爆de美女2
Sell the barbecue as says father du breul2
Beautiful vacuum girl3
The real super beauty8
The money of more than 100 countries and regions15
做运动的校花1
Look at the Spring Festival people crowded into the what kind
Download software ranking
linux高级编程
The Bermuda triangle1
Unix video tutorial10
Dance with duck(male prostitution)
VC++6.0培训教程
尖东毒玫瑰A
Macromedia Dreamweaver 8
Boxer's Top ten classic battle9
WebService在.NET中的实战应用教学视频 → 第1集
matrix2
qq published in(发表于) 2014/7/11 9:17:23 Edit(编辑)
C#中MaskedTextBox控件的用法以及实例

C#中MaskedTextBox控件的用法以及实例

C#中MaskedTextBox控件的用法以及实例

MaskedTextBox控件

1.功能

MaskedTextBox控件使用掩码区分正确和不正确的用户输入。MaskedTextBox控件,如图1所示。



图1 MaskedTextBox控件

2.属性

MaskedTextBox控件常用属性及说明如表1所示。



表1 MaskedTextBox控件常用属性及说明

下面详细介绍ValidatingType属性,该属性可以获取或设置用于验证用户输入数据的数据类型。

语法:

public Type ValidatingType { get; set; }

属性值:表示在验证中使用的数据类型的Type。默认为空引用。

示例

ValidatingType属性

把ValidatingType属性值设置为日期类型。

程序主要代码如下:

maskedTextBox1.ValidatingType = typeof(System.DateTime);

3.方法

(1)ClearUndo方法。该方法主要用于从文本框的撤消缓冲区中清除最近操作的信息。

(2)ValidateText方法。该方法主要用来将用户输入的字符串转换为验证类别的一个实例。

语法:

public Object ValidateText ()

返回值:如果转换成功,则为由ValidatingType属性指定的类型的Object;否则,将返回空引用,以指示转换失败。

4.事件

MaskedTextBox控件常用事件及说明如表2所示。



表2 MaskedTextBox控件常用事件及说明

下面详细介绍MaskInputRejected事件,该事件在用户的输入或者分配的字符与输入掩码的对应格式元素不匹配时发生。

语法:

public event MaskInputRejectedEventHandler MaskInputRejected

说明:MaskInputRejected是MaskedTextBox类的默认事件。

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_18

{

static class Program

{

///

本教程来自http://www.isstudy.com/

/// 应用程序的主入口点。

///


[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

{

/// 本教程来自http://www.isstudy.com/

/// 必需的设计器变量。

///


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 窗体设计器生成的代码


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.