Validating WinForms TextBox (in C#)

前端 未结 5 1873
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 14:53

In TextBox_Leave event i need to check whether numbers entered in textbox is in serial number or not.If it is not in order then i need to display a message as \"number\" is

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 14:55

    I will show you how to validate Validating WinForms TextBox (in C#).

    1. Create a function:

      public static void ChkBlankTextBoxes(object sender, string type)
      {
      
          if (sender is TextBox)
          {
              TextBox textbox = sender as TextBox;
              if (string.IsNullOrEmpty(textbox.Text))
              {
                  MessageBox.Show("Please enter correct value value..");
                  textbox.Focus();
      
              }
          }
      }
      
    2. Call to created function:

      ChkBlankTextBoxes(txt_userID, textBoxtype);
      
      ChkBlankTextBoxes(txt_password, textBoxtype);
      

提交回复
热议问题