Buttons with images on are sometimes a lot easier to use than text based buttons - and can take up less space where it gets critical. But ... it can be confusing to get them into the app so they are available as Image objects directly, compiled into your app. So I thought I'd write it down for next time I have to do it so I - and maybe you - have an easier time.
Introduction
Buttons with images on are sometimes a lot easier to use than text based buttons - and can take up less space where it gets critical.
But ... it can be confusing to get them into the app so they are available as Image objects directly, compiled into your app.
So I thought I'd write it down for next time I have to do it so I - and maybe you - have an easier time.
Background
First, create a folder to put them in: right click your project and select "Add ... New Folder". Rename it to "Resources".
Right click the "Resources" folder, and select "Add ... New Folder" - rename this to "Images"
Right click the Images folder and select "Add ... Existing Item". Browse to the images (you may need to change the "type" dropdown) and select all those you are interested in. Add them to the project.
In the Images folder, highlight all the images you just added, and look at the properties pane. The "Build Action" will be set to "Content" - change it to "Embedded Resource".
Open the "Resources.resx" file of your project.
Select "Images" at the top left. Drag and drop the Images folder onto the .resx window.
Open your code, and you can get the Image
object like this:
Image i = Properties.Resources.NameOfImageWithoutExtension;
Or set it as the Image
property for a Button
or PictureBox
for example.
History
- 17th April, 2023: First version
- 17th April, 2023: A few minutes later ... Why did half the images disappear? Re-inserted
- 17th April 2023: Images re-uploaded, and re-re-inserted.