Q:

Button background image changes on mouseover and mousedown events

I am creating a windows forms application and I want the background image of button5 to change on mouseover and mousedown events. The images in resources are "1.jpg" and "2.jpg".
When I have the cursor over the button I want "2.jpg" as background image and "1.jpg" otherwise.
I don't get any errors. I use this code:
public Form1()
    {
        InitializeComponent();
        button5.MouseEnter += new EventHandler(button5_MouseEnter);
        button5.MouseLeave += new EventHandler(button5_MouseLeave);
    }

    void button5_MouseLeave(object sender, EventArgs e)
    {
        this.button5.BackgroundImage = ((System.Drawing.Image)(Properties.Resources._1));
    }

    void button5_MouseEnter(object sender, EventArgs e)
    {
        this.button5.BackgroundImage = ((System.Drawing.Image)(Properties.Resources._2));
    }

What seems to be the problem ? Should i use something else to do this?
I would also want to know how do i completely remove the border of a button.
Thanks a lot!
Vlad

A:

Your code should be fine this way (just make sure your events are added in your designer partial class, not in the constructor). If the control does not refresh, maybe the form or the control is busy, so you can try and refresh the button with its Refresh() method.
To remove the border of a button, set the control's FlatStyle to Flat and FlatAppearance.BorderSize to 0.

