开发者

how to programmatically change the background image on form c#

开发者 https://www.devze.com 2022-12-12 14:43 出处:网络
I need to change the开发者_如何学Go background image of my form when i klick a button, and change it back to null again the second time it is clicked, how can i do this?Use BackgroundImage property:

I need to change the开发者_如何学Go background image of my form when i klick a button, and change it back to null again the second time it is clicked, how can i do this?


Use BackgroundImage property:

form.BackgroundImage = image;

to hide the image:

form.BackgroundImage = null;

Put this source code to ClickButton method:

form.BackgroundImage = form.BackgroundImage == null ? image : null;


You should be able to set the BackgroundImage property of your form from the event handler of that button.

For example you could do it like this:

this.BackgroundImage = new Bitmap(@"c:\Temp\image.bmp");

In order to remove the image, set the property back to null.

The image can also come from a resource.

0

精彩评论

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