本文整理汇总了C#中System.Windows.Forms.MaskedTextBox.TypeValidationCompleted事件的典型用法代码示例。如果您正苦于以下问题:C# MaskedTextBox.TypeValidationCompleted事件的具体用法?C# MaskedTextBox.TypeValidationCompleted怎么用?C# MaskedTextBox.TypeValidationCompleted使用的例子?那么恭喜您, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.Windows.Forms.MaskedTextBox
的用法示例。
在下文中一共展示了MaskedTextBox.TypeValidationCompleted事件的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
maskedTextBox1.Mask = "00/00/0000";
maskedTextBox1.ValidatingType = typeof(System.DateTime);
maskedTextBox1.TypeValidationCompleted += new TypeValidationEventHandler(maskedTextBox1_TypeValidationCompleted);
maskedTextBox1.KeyDown += new KeyEventHandler(maskedTextBox1_KeyDown);
toolTip1.IsBalloon = true;
}
void maskedTextBox1_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
{
if (!e.IsValidInput)
{
toolTip1.ToolTipTitle = "Invalid Date";
toolTip1.Show("The data you supplied must be a valid date in the format mm/dd/yyyy.", maskedTextBox1, 0, -20, 5000);
}
else
{
//Now that the type has passed basic type validation, enforce more specific type rules.
DateTime userDate = (DateTime)e.ReturnValue;
if (userDate < DateTime.Now)
{
toolTip1.ToolTipTitle = "Invalid Date";
toolTip1.Show("The date in this field must be greater than today's date.", maskedTextBox1, 0, -20, 5000);
e.Cancel = true;
}
}
}
// Hide the tooltip if the user starts typing again before the five-second display limit on the tooltip expires.
void maskedTextBox1_KeyDown(object sender, KeyEventArgs e)
{
toolTip1.Hide(maskedTextBox1);
}