繁体   English   中英

在C#中设置按钮的背景图像

[英]Setting background image of button in C#

我想将图像设置为Windows窗体按钮的背景。

该图像将添加到项目的资源中。

我该怎么做呢?

只需设置Button的BackgroundImage属性即可。 一个例子:

button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Image));

在加载应用程序或进行设置时都可以使用它。

button.BackgroundImage = YourApplicationNamespace.Properties.Resources.yourImageHere;

在Visual Studio中,您可以执行以下操作:

  1. 转到按钮的属性,然后单击BackgroundImage项。
  2. 点击“ ...”图标。
  3. 点击“本地资源”旁边的单选按钮。
  4. 点击“导入”,然后选择您想要的项目作为背景。
  5. 然后,点击“确定”。

或者,您可以通过代码执行以下操作:

button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Image));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM