vb.net - Is it bad practice to handle multiple event types of the same action? -
my problem:
i have .enter
, .textchanged
events both fire exact same code. i've combined these events under 1 handler. considered bad practice reason or in particular instance, considered wise streamline code?
combined under 1 handler:
private sub textbox_enterchanged(byval sender system.object, byval e system.eventargs) handles textbox1.enter, textbox2.enter, textbox1.textchanged, textbox2.textchanged 'some action. end sub
default separate handlers:
private sub textbox_enter(byval sender system.object, byval e system.eventargs) handles textbox1.enter, textbox2.enter 'some action. end sub private sub textbox_textchanged(sender object, e eventargs) handles textbox1.textchanged, textbox2.textchanged 'the same action. end sub
while asking "bad practice" can lead overly big arguments based on opinion, have done same. it's legal, functional, , clear (unless start handling huge list of events). reply question straight question:
conversely, benefit of copy/pasting identical code multiple methods?
so, no, not consider bad practice.
vb.net winforms visual-studio events event-handling
No comments:
Post a Comment