I'm trying to change the image of a button in different situations. The only thing it will do is adding the new (smaller) image ontop of the old (wider) image. How can i make sure the old image will be cleared. I can't find button.image.clear or something.
if (Global.van_zoek)
{
btnterug.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.ZoekBedrijf2));
}
else if (!diftext)
{
btnterug.BackgroundImage = ((System.Drawing.Im开发者_C百科age)(Properties.Resources.AlleBedrijven2));
}
else if (_Prparent != null)
{
btnterug.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.InfoContact2));
}
else
{
btnterug.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.InfoProject2));
}
http://img225.imageshack.us/i/imageprobl.jpg/
//Change old image to null
btnterug.BackgroundImage = null;
//Load New Image
btnterug.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.InfoProject2));
Try to use invalidate method:
button2.Invalidate();
You Could just set the source to null before you change it to the new image.
Are you getting Button.Image
and Button.BackgroundImage
confused?
精彩评论