我正在使用Devexpress
当我希望用户有两个日期时,我有一个TextEdit,如下所示:
dd/MM/yyyy - dd/MM/yyyy (例如: 02/12/2011-03/09/2013 )
我试着像上面那样设置遮罩,但不起作用。
发布于 2019-08-12 04:16:42
可以设置掩码:
textEdit.Properties.Mask.MaskType = MaskType.Simple;
textEdit.Properties.Mask.EditMask = "00/00/0000-00/00/0000";但是,TextEdit只能有一个EditValue属性,因此它不允许存储两个DateTime值。
您可以通过验证事件添加自定义验证:
private void TextEdit_Validating(object sender, CancelEventArgs e)
{
string textValue = (string)(sender as TextEdit).EditValue;
var dates = textValue?.Split('-').Select(x => { DateTime.TryParse(x, out DateTime result); return result; });
if (dates == null || dates.Any(x => x == null))
{
e.Cancel = true;
}
}但是它看起来很混乱,所以我建议你使用两个DateEdit控件来代替。
https://stackoverflow.com/questions/57451993
复制相似问题