name for button does not change in click event

I have 2 buttons name btnHonda and btnToyota, but the click event clicks show:

privatevoid button1_Click(object sender,EventArgs e)

{

}

privatevoid btnToyota_Click(object sender,EventArgs e)

{

}

button1_Click should be btnHonda_click .....is this a bug with Visual C# 2005?

[892 byte] By [TienTran] at [2008-2-28]
# 1
Hi,
This haven't happened to me before. Could you reproduce it? Provide us some steps? Does the code in the ambiguos name executes when you press the button?

cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# IDE...
# 2
hi Paul,
This is very simple. First, I add the first button to an empty form (form1) --> change the name in property to btnToyota --> double click on the button, in form1.cs it shows

private void btnToyota_Click(object sender, EventArgs e)

{

}

Then I add a second button, double click on the button (button name is still button1), in form1.cs it shows

private void button1_Click(object sender, EventArgs e)

{

}
Now, I change the second button name (button1) to btnHonda and double click the button again. In form1.cs, button1_Click is still there. Shouldn't it be changed to btnHonda_Click?

The code still runs without any problem though.

I think Visual Studio 2003 does the same thing too ....
Thanks for all reponse!

Tien Tran


TienTran at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# IDE...
# 3
Hi,
Ok, I reproduced it. Well, I think this would be considered as by design. On default, the name of the object would be used on an event. But also, you have the capability of naming you own event (In the properties toolbox, click on the lightning button), I guess this is the reason why the IDE doesn't automatically change the event name into the new object name.
Also, multiple controls could be sharing a single event procedure. Button1 and Button2 could be executing clickMe() event and If I rename Button1 should the event also be renamed?

BTW, if you want to change your event's name, you could do it manually in the properties toolbox...

cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# IDE...