开发者

C# changing image of a button just paste's the new image ontop of the old image

开发者 https://www.devze.com 2023-02-19 05:01 出处:网络
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

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消