c# - overriding Form's OnFormClosing for validation -


i'm planning on overriding onformclosing (of system.windows.forms.form) perform validation of user input dialog. if validation fails, set formclosingeventargs's cancel property true:

protected override void onformclosing(formclosingeventargs e) {     if (dialogresult == dialogresult.ok)     {         if (!isdialoginputvalid())         {             e.cancel = true;             return;          // not calling base class onformclosing okay here?         }     }     base.onformclosing(e); } 

my question: should calling base class' onformclosing when cancel close (that is, should remove return above)?

my current thinking should not call it, since delegates attached formclosing event wouldn't expect called when dialog has decided not closing. on other hand, i'm nervous perhaps base class' onformclosing other necessary stuff.

fyi, i'm new winforms, advice on how should performing validation (if not best approach) appreciated.

related link: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing.aspx

it looks fine. design of application , base form determine whether or not appropriate call base.onformclosing(e) , when call it(at start or end) i.e. if had custom code in base method.

looking @ example, there reason overriding onformclosing? couldn't/shouldn't doing validation dialogresult set ok? if input not valid, dialog shouldn't set ok , close() should not called. onformclosing used handle cleanup , prompt user asking them if want cancel current task (usually used when hit x on form).

back 1 of questions @ hand, safe in calling return if inputs not valid. there's no reason call base.onformclosing() if you're not going close. whether want call base.onformclosing() or not based on logic have in base method.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -