Guest User

HasText in TextBox

a guest
Aug 19th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1.     class ExTextBox : TextBox, INotifyPropertyChanged
  2.     {
  3.         /// <summary>
  4.         /// Gets whether the control contains text
  5.         /// </summary>
  6.         //[Browsable(false)]
  7.         [Bindable(true)]
  8.         public bool HasText
  9.         {
  10.             get { return TextLength > 0; }
  11.         }
  12.  
  13.         protected override void OnTextChanged(EventArgs e)
  14.         {
  15.             base.OnTextChanged(e);
  16.             OnPropertyChanged("HasText");
  17.         }
  18.  
  19.         public event PropertyChangedEventHandler PropertyChanged;
  20.         protected void OnPropertyChanged(string propertyName)
  21.         {
  22.             if (PropertyChanged != null)
  23.             {
  24.                 var args = new PropertyChangedEventArgs(propertyName);
  25.                 PropertyChanged(this, args);
  26.             }
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment