You can use the Name property:
switch( ((Button)sender).Name)
{
case "Button1":
// :
break;
case "Button2" :
// :
break;
}
But the real answer is.... If you want to do something different for
each button, you should be using separate Click events. Factor the common
part into a separate method, and call it from each of the Button[n]_Click
events.
--
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home:
www.noveltheory.com Work:
www.njtheater.com
Blog:
www.honestillusion.com Day Job:
www.partsearch.com
"Frank Esser" <Mi*****@nurfuerspam.de> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl...
Hi !
I have several buttons and a common click event for all of them. How can I
get the reference to the clicked control in a switch?
This does not work:
private void Button_Click(object sender, System.EventArgs e)
{
switch ((Button)sender)
{
case Button1:
...
break;
case Button2:
....
break;
default:
break;
}
}