我有一个TextBox UserControl。我为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...,
}
我向您展示Windows窗体中UserControl属性的图像
现在我想验证用户何时更改该属性中的值...,
答案 0 :(得分:2)
实现一个自定义setter,检查该值是否有效。
public int MaximumLength
{
get
{
return this.maximumLength;
}
set
{
if(value <= 4)
{
MessageBox.Show("Value is too small.");
}
else this.maximumLength = value;
}
}
编辑:所以实现一个getter。