如何以编程方式更改窗体上的背景图像#

发布于 2024-08-12 10:04:27 字数 61 浏览 3 评论 0原文

当我单击按钮时,我需要更改表单的背景图像,并在第二次单击按钮时再次将其更改回 null,我该如何执行此操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧梦荧光笔 2024-08-19 10:04:27

使用BackgroundImage属性:

form.BackgroundImage = image;

隐藏图像:

form.BackgroundImage = null;

将此源代码放入ClickButton方法中:

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

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;
叫嚣ゝ 2024-08-19 10:04:27

您应该能够从该按钮的事件处理程序设置表单的BackgroundImage 属性。

例如你可以这样做:

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

要删除图像,请将属性设置回 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文