简体   繁体   English

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

[英]Setting background image of button in C#

I want to set an image as background of a button of Windows Forms. 我想将图像设置为Windows窗体按钮的背景。

The image is added to the project´s resources. 该图像将添加到项目的资源中。

How do I do this? 我该怎么做呢?

Simply set the BackgroundImage property of the Button. 只需设置Button的BackgroundImage属性即可。 An example: 一个例子:

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

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

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

In Visual Studio, you can do this: 在Visual Studio中,您可以执行以下操作:

  1. Go to the properties for your button and click the BackgroundImage item. 转到按钮的属性,然后单击BackgroundImage项。
  2. Click the '...' icon. 点击“ ...”图标。
  3. Click the radio button next to 'Local Resource'. 点击“本地资源”旁边的单选按钮。
  4. Click 'Import' and select the item you wish to have as the background. 点击“导入”,然后选择您想要的项目作为背景。
  5. Then, click 'Ok'. 然后,点击“确定”。

Or, from code you can do this: 或者,您可以通过代码执行以下操作:

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

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

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