[英]UserControl TextBox Validation in C#
我有一個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屬性的圖像
現在我想驗證用戶何時更改該屬性中的值...,
實現一個自定義setter,檢查該值是否有效。
public int MaximumLength
{
get
{
return this.maximumLength;
}
set
{
if(value <= 4)
{
MessageBox.Show("Value is too small.");
}
else this.maximumLength = value;
}
}
編輯:所以實現一個getter。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.