how to programmatically change the background image on form c#

本小妞迷上赌 提交于 2020-01-03 15:30:33

问题


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?


回答1:


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;



回答2:


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.



来源:https://stackoverflow.com/questions/1789967/how-to-programmatically-change-the-background-image-on-form-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!