TheMrRafus
TheMrRafus

Reputation: 35

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?

Upvotes: 2

Views: 35239

Answers (3)

Kyle Colantonio
Kyle Colantonio

Reputation: 454

You would use this when you load your application, or whenever you want to set it.

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

Upvotes: 6

Brian
Brian

Reputation: 5119

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));

Upvotes: 2

dsfgsho
dsfgsho

Reputation: 2769

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

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

Upvotes: 3

Related Questions