Put Visual Studio resource files in a folder other than "Resources"?

I have a resource file called rs.resx . In the Visual Studio designer, I can add an image to my resource file by clicking "Add Resource" and specifying the path to the image file.

After adding the image, the image file itself is also copied to a folder in my Visual Studio solution called Resources . I would like all my image files to be placed in a folder called Images . Is it possible?

+8
c # visual-studio resources winforms
source share
2 answers

It is a little complicated, but it is possible.

VS checks if the file added to the resource has already been defined somewhere in your project. If he cannot find it, he creates the “Resources” folder, places a copy of the file there, adds this file to the project and places a link in the resource constructor to this fresh copy of your file.

To avoid this behavior, you must add the file to your project before adding it to the resource file. If the file is not in the structure of your project, you can simply create a folder, right-click on it, select "Add File" and, before clicking the "Add" button in OpenFileDialog, click on the small arrow next to the button and select "Add as". link.

Now the file is located in the same place on your hard drive where you want, and the resource designer does not create a copy in the project file if you now add the file to the resource designer.

Maybe this small picture helps you find the Add button as a link: Add as link
(source: modbusdriver.com )

+5
source share

This is just a subdirectory of your project directory. Your program does not use it at run time, it must use the built-in resources. Everything that you add to the .resx file is copied there, not just images. But you can rename the folder if you want, right-click on it and click "Rename".

Instead of adding the .resx file to your project, I would recommend using an existing one. Project + Properties, Resources. Easily retrieves a resource at runtime, just use Properties.Resources. Something in your code.

+2
source share

All Articles