我的要求是用户将在屏蔽文本框中输入时间(“HH:mm:ss”),并根据该时间我正在做一些功能。我的问题是我可以屏蔽时间,但我不能限制用户最多输入 23 小时、59 分钟和 59 秒。如何解决这个问题。
C# 代码
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");
}