how to programmatically change the background imag

2019-06-20 18:05发布

I need to change the 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?

2条回答
做个烂人
2楼-- · 2019-06-20 18:21

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.

查看更多
等我变得足够好
3楼-- · 2019-06-20 18:25

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;
查看更多
登录 后发表回答