Inherit from the System.Windows.Forms.Button class, and override the following methods:
- OnMouseDown, this handles your "Pressed Image"
- OnMouseEnter, this handles your "Hovering Image"
- OnMouseLeave, and this handles your original image
The code would look something like this:
public class MyButton : System.Windows.Forms.Button {
public MyButton()
: base() {
// No default implementation
}
protected override void OnMouseDown(Object sender, MouseEventArgs e) {
this.Image = Properties.Resources.PressedImage;
}
protected override void OnMouseEnter(Object sender, MouseEventArgs e) {
this.Image = Properties.Resources.HoveringImage;
}
protected override void OnMouseLeave(Object sender, MouseEventArgs e) {
this.Image = Properties.Resources.DefaultImage;
}
}
Now since you have multiple buttons, you could of course turn the resource acquisitions into properties.
public Image DefaultImage {
get;
set;
}
public Image PressedImage {
get;
set;
}
public Image HoveringImage {
get;
set;
}
And use those in the overridden, virtual methods. This is probably your best approach. I would avoid the answer below (no offense Phoexo) as it is a very unusual and messy solution.
Once you write and compile the new button, you can do a simple find and replace to change the existing button's types. You will have to do a little cleanup and set the three properties for each button to their corresponding images, and cleanup some designer code, but this will make your life easier in the long run if you have to add more buttons.