Event Names Keep Changing

Sometimes randomly buttons will stop working, and it turns out that its because the event method name has changed.  For example:
private void button1_Click(object sender, EventArgs e)
to
private void button1_Click_1(object sender, EventArgs e)

Is there anyway to stop this from happening?  OR to easily change the code when it does?  As currently I have to cut all code from the original button click event to the new one.
LVL 15
angus_young_acdcAsked:
Who is Participating?
 
SameerJagdaleConnect With a Mentor Commented:
in design view, you get the events information in properties grid (watch the lightning bolt) select the appropriate event (in your case it is click), then from drop down select the event you wish to subscribe.
Does it make sense?
0
 
angus_young_acdcAuthor Commented:
Hi yes I understand, its just rather annoying to have to do that for each individual control.  So I was hoping for a simpler solution if there  was one.
0
 
SameerJagdaleCommented:
you can do the changes in initializecomponent directly.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"Sometimes randomly buttons will stop working, and it turns out that its because the event method name has changed"

This isn't a "random" event...this happens when you CUT and PASTE a control from one place to another.  When you Cut the control the handler is automatically removed.  Then when you Paste it again and and rewire it...the IDE sees that there is already an existing method with the name it wants (from the previous stub handler) and so it creates a new method stub by adding the number after it.

0
 
angus_young_acdcAuthor Commented:
I know that it happens when you cut/paste controls, however I have not been doing that which is why I see it as randomly changing.  They are not even being moved anywhere (and there is no panel to be their parent).
0
 
angus_young_acdcAuthor Commented:
Can anybody help solve this?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
We already listed the common cause of this and you said that wasn't it...not sure what else to suggest!
0
All Courses

From novice to tech pro — start learning today.