Validating WinForms TextBox (in C#)

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

    I don't know whether this also works in c#2.0, this is my experience in c#3.0:

    Why do you use TextBox_Leave for that? The Validating-event should be used for validating whether input is correct.

    Combine using the Validating-event with using an ErrorProvider (you can just drag it from the toolbox onto the form) to set an error message: it will be displayed as a (blinking) exclamation mark in a red triangle.

    An ErrorProvider can also block any submit-actions.

提交回复
热议问题