Reputation: 1
What I'm trying to do is find out which control is clicked in my application without call MouseClick
handler multi times for every control.
Assume that we have a form which contains some controls and then one of them is clicked by user and a Messagebox pups up and shows which control is clicked.
In other word there is just one handler with a sender argument so that sender tell me which control is clicked.
Something like below code:
private void MouseClicked(object sender, EventHandler e)
{
if(sender is Button)
{
//do something
}
if (sender is Label)
{
//do something else
}
/*
* .
* .
* .
*
*/
}
Upvotes: 0
Views: 763
Reputation: 3007
Simply select all the controls from the designer of the form and go to the events tab.
Double click on the mouse click event and one handler would be generated for those events.
Upvotes: 2