Validating WinForms TextBox (in C#)

前端 未结 5 1825
没有蜡笔的小新
没有蜡笔的小新 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 15:19

    Alternatively you can also use Validating event of the text box.

      private void textBox1_Validating( object sender, CancelEventArgs e )
      {
          if ( textBox1.Text == "3" )
              e.Cancel = true;
      }
    

    The text-box wont loose focus until it receives a valid input.

提交回复
热议问题