Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1.         protected override void OnTextChanged(EventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 if (!string.IsNullOrEmpty(this.Text))
  6.                 {
  7.                     int maxLength = InputType == InputTypeEnum.Dec ? 3 : 2;
  8.                     if (Text.Length > maxLength)
  9.                     {
  10.                         StringBuilder removedText = new StringBuilder();
  11.                         Text = removedText.Append(this.Text).Remove(maxLength, this.Text.Length - maxLength).ToString();
  12.                     }
  13.                     if (Convert.ToInt32(this.Text, (int)InputType) > 255)
  14.                         Text = InputType == InputTypeEnum.Dec ? "255" : "FF";
  15.                     else if (Convert.ToInt32(this.Text, (int)InputType) < 0)
  16.                         Text = "00";
  17.                 }
  18.                 base.OnTextChanged(e);
  19.             }
  20.             catch { this.Text = "0"; }
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement