How to skip Validating after clicking on a Form's Cancel button

前端 未结 17 1223
一生所求
一生所求 2020-12-08 04:04

I use C#. I have a Windows Form with an edit box and a Cancel button. The edit box has code in validating event. The code is executed every time the edit box loses focus. Wh

17条回答
  •  -上瘾入骨i
    2020-12-08 04:51

    Create a bool:

    bool doOnce;
    

    Set it to false in your function and then:

    if (doOnce == false)
    {
        e.cancel = true;
        doOnce = true;
    }
    

    This means it will only run once and you should be able to cancel it. This worked for me anyways.

提交回复
热议问题