窗体上有很多控件,用来设置一些参数,需要在点击OK时对所有的参数进行验证,如果有参数无效则显示错误信息,效果如下:
首先,需要为控件添加验证事件
正常情况下,应该是控件的焦点发生变化时才会触发Validated事件,下面是MSDN的一些资料
When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl.ActiveControl property to the current form, focus events occur in the following order: