My requirement is that the user will enter a time ("HH:mm:ss") in masked text box and based on that time i am doing some functionalities. My problem is i can mask the time but i can't restrict the user to enter up to 23 for hours,59 for minutes and 59 for seconds. How to fix this.
C# Code
private void Form1_Load(object sender, EventArgs e)
{
maskTxtAlert1.Mask = "00:00:00";
maskTxtAlert1.CutCopyMaskFormat = MaskFormat.ExcludePromptAndLiterals;
}
private void maskTxtAlert1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
if (e.Position == maskTxtAlert1.Mask.Length)
{
string errorMessage = "You cannot add extra characters";
toolTip1.ToolTipTitle = "Input Rejected - No more inputs allowed";
toolTip1.Show(errorMessage, maskTxtAlert1, 12, 24, 2000);
errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
errorProvider1.SetError(maskTxtAlert1, errorMessage);
}
else
{
toolTip1.ToolTipTitle = "Input Rejected";
string errorMessage = "You can only add numeric characters (0-9).";
toolTip1.Show(errorMessage, maskTxtAlert1, 12, 24, 2000);
errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
errorProvider1.SetError(maskTxtAlert1, errorMessage);
}
}
private void maskTxtAlert1_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
{
MessageBox.Show("Enter Valid as One");
}