I have a TextBox UserControl. I create a Dynamic Property for the Textbox for MaximumLength.
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
Now i want to verify when user change the value in that property...,
Implement a custom setter that checks if the value is valid.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.