c# - Combining Multiple Event Methods -
looking refactor application code. have gui has several of same events reflected different labels, textboxes, etc...
for example:
private void textbox1_enter(object sender, eventargs e) { textbox1.backcolor = color.lightcyan; }
and
private void textbox2_enter(object sender, eventargs e) { textbox2.backcolor = color.lightcyan; }
i assign these methods event on object properties in visual studio. there efficient way combine multiple event methods clean code? thanks!
define single event like:
private void textbox_enter(object sender, eventargs e) { textbox textbox = sender textbox; if (textbox != null) textbox.backcolor = color.lightcyan; }
and assign event textbox come in event like:
textbox1.enter += textbox_enter; //same event handler textbox2.enter += textbox_enter; //same event handler
c# visual-studio events
No comments:
Post a Comment