c# - Skip validation with controlbox[X] of winform? -


this question has answer here:

i have validating event

private void employeeidtextbox_validating(object sender, canceleventargs e) {    if (employeeidtextbox.text == "")    {       messagebox.show("please enter employeeid.", "invalid employeeid");    } } 

and able skip validation cancelbutton

private void cancelbutton_click(object sender, eventargs e) {     autovalidate = autovalidate.disable;     close(); } 

is possible skip validation controlbox[x] of windowsform? tried set causesvalidation of form false not working. try formclosing not working.

private void form1_formclosing(object sender, formclosingeventargs e) {    if (employeeidtextbox.causesvalidation)    {       employeeidtextbox.causesvalidation = false;       close();    } } 

i gave answer in previous question. stop using messagebox , problem disappears. use errorprovider component instead.

intercepting form's closing handling can cancel validation before first event fires requires hack. paste code form:

    protected override void wndproc(ref message m) {         // intercept wm_syscommand, sc_close         if (m.msg == 0x112 && (m.wparam.toint32() & 0xfff0) == 0xf060) this.autovalidate = autovalidate.disable;         base.wndproc(ref m);     } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -