How to programmatically change background image on C # form

I need to change the background image of my form when I press the button and change it to zero again the second time it is pressed, how can I do this?

+5
source share
2 answers

Use the BackgroundImage property:

form.BackgroundImage = image;

to hide the image:

form.BackgroundImage = null;

Put this source code in the ClickButton method:

form.BackgroundImage = form.BackgroundImage == null ? image : null;
+15
source

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

For example, you can do this as follows:

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

, null.

.

+9