Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to programmatically change the background image on form c#

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?

like image 327
Darkmage Avatar asked Nov 24 '09 13:11

Darkmage


People also ask

How to change the background color of a form in c#?

To change the background color, select the form in Visual Studio and locate the BackColor property in the Properties panel. There are a number of ways to specify a color. Color by name - Simply type in a color name into the BackColor value field (for example Red, Yellow, Cyan etc).

How do I change the background in Windows form?

Set the background in the Windows Forms DesignerSelect the Custom tab to display a palette of colors. Select the Web or System tab to display a list of predefined names for colors, and then select a color.


1 Answers

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;
like image 128
Michał Ziober Avatar answered Sep 17 '22 17:09

Michał Ziober