简体   繁体   中英

Setting background image of button in C#

I want to set an image as background of a button of Windows Forms.

The image is added to the project´s resources.

How do I do this?

Simply set the BackgroundImage property of the Button. An example:

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

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

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

In Visual Studio, you can do this:

  1. Go to the properties for your button and click the BackgroundImage item.
  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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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