Button1_Click not used

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I had a project where I had some code in my Button1_Click procedure and
copied it over to a new project (that had the same button name on it) and I
couldn't figure out why the event never fired.

I then double-clicked on the button and a new event opened which normally
would have been Button1_Click, but in this case it was Button1_Click_1. I
assume this was because I had manually put in the Button1_Click event.

Why did it do that?

Does that mean I can't manually put in my code without first using the
Design Screen first, Double clicking the object I want to add code to and
then add it to the procedure IT puts in?

Thanks,

Tom
 
tshad said:
I had a project where I had some code in my Button1_Click procedure and
copied it over to a new project (that had the same button name on it) and I
couldn't figure out why the event never fired.

If you just copy over the method, that doesn't add the required EventHandler
for the button1->Click event. There's nothing magic about the Button1_Click
name (even though it looks it).
I then double-clicked on the button and a new event opened which normally
would have been Button1_Click, but in this case it was Button1_Click_1. I
assume this was because I had manually put in the Button1_Click event.

Why did it do that?

Since a Button1_Click method already exists, VS assumes that it can't use
that name when it generates code.
Does that mean I can't manually put in my code without first using the
Design Screen first, Double clicking the object I want to add code to and
then add it to the procedure IT puts in?

Not at all. In this case, you could go to the designer, select the button,
click on the Event button in the Properties Window, and enter the method
name in the Click entry. This will generate an EventHandler for the button's
Click event using whatever method you put in.
 
Back
Top