Reputation: 23
I am creating a windows forms application in visual studio 2010. I need to make a button that has a different image that changes on mouseover and mousedown events.
I used this:
public Form1()
{
InitializeComponent();
button1.MouseEnter += new EventHandler(button1_MouseEnter);
button1.MouseLeave += new EventHandler(button1_MouseLeave);
}
void button1_MouseLeave(object sender, EventArgs e)
{
this.button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.img1));
}
void button1_MouseEnter(object sender, EventArgs e)
{
this.button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.img2));
}
i saved the images in resources as "img1" and "img2". However, they are not recognised.
this.button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.img2));
what to put instead of "img2" in this example ? How to access the image from resources? the button also has a bevel-border. How to remove it?
Hope i made myself clear and you understand my problem... Vlad
Upvotes: 1
Views: 1506
Reputation: 3777
looks like your Resources.resx file is located under Properties folder. Go to your project Root folder and then expand "Properties" folder and you should see "Resources.resx" file. double click on it and it should open the screen with list of resources.
First menu item in the new screen allows you to see resources by type. select "Images" and you should see what you have attached to your resources. You can also add more resources to it.
Attaching file to project doesnt mean that it will get added to Resources, you will have to manually add it using above screen so that you can use:
Properties.Resources.Img2
Upvotes: 2