If I understand correctly, you want to change the color only of the button which is hovered?
You can do it like this:
private void ChangeColourOnMouseEnter(object sender, EventArgs e)
{
((Button)sender).BackColor = Color.blue;
}
private void ChangeColourOnMouseLeave(object sender, EventArgs e)
{
((Button)sender).BackColor = Color.Yellow;
}
The
sender
parameter holds a reference to the control which has raised the event.
This code first casts the
sender
variable (declared as
object
) back to its real type (
Button
), then call its
BackColor
property to assign it a different color.
Finally, select all the buttons you want to have that behaviour, and in the Properties panel, click on the Events button (at the top, just under the name and type of the control); assign the event handlers to corresponding events. The same event handler will then be able to handle the event for each of these controls.
Hope this helps.