[英]UserControl TextBox Validation in C#
I have a TextBox UserControl. 我有一个TextBox UserControl。 I create a Dynamic Property for the Textbox for MaximumLength.
我为MaximumLength的Textbox创建了一个动态属性。
public int MaximumLength { get; set; }
private void txtLocl_KeyPress(object sender, KeyPressEventArgs e)
{
txtLocl.MaxLength = MaximumLength;//txtLocl is a Usercontrol Textbox..,
//txtLocl maxLength should be given by the user in WindowsForm
//that should be come to here...,
}
I show you the Image of the UserControl Properties in Windows Form 我向您展示Windows窗体中UserControl属性的图像
Now i want to verify when user change the value in that property..., 现在我想验证用户何时更改该属性中的值...,
Implement a custom setter that checks if the value is valid. 实现一个自定义setter,检查该值是否有效。
public int MaximumLength
{
get
{
return this.maximumLength;
}
set
{
if(value <= 4)
{
MessageBox.Show("Value is too small.");
}
else this.maximumLength = value;
}
}
Edit: So implement a getter. 编辑:所以实现一个getter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.