I've got a rather large solution with many projects in it. Ideally I'd like to create a Resources project that contains all the embedded icons I need throughout my application.
I've read articles where people are referencing them through code, but is it possible to get access to this project's resources in the designer? In other words, I'd like to select the resources when clicking on the BackgroundImage property of a form in the designer.
If not, what sort of architecture should I consider when trying to decouple my resources from my main project? It's probably not a smart idea to release a 100mb executable everytime I modify a line of code or two.
Hence, WinForms is clearly a front-end thing. Show activity on this post. Front-end technology can essentially apply to any technology that is primarily used to build applications' user experiences. This can include WinForms, Win32's windowing API's, MFC, Silverlight, Javascript, HTML, CSS.
I've found a working way to share a resources file between many projects and keep VS Designer compatibility (works with VS 2012), it is no complicated :
Create a new resources file in your source project (named in my example SharedResources.resx)
Open SharedResources.resx in Designer and change Access Modifier
to Public
Open the .csproj
of your new project file with notepad and add following code into the <ItemGroup>
which contains the <compile Include="MyForm.cs">
: (will include *.resx and *.Designer.cs as link without compilation and with special namespace)
<EmbeddedResource Include="MY_SOURCE_PROJECT_FOLDER\Properties\SharedResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<Link>SharedResources.resx</Link>
<LastGenOutput>SharedResources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
<CustomToolNamespace>MY_SOURCE_PROJECT_NAMESPACE.Properties</CustomToolNamespace>
</EmbeddedResource>
<None Include="MY_SOURCE_PROJECT_FOLDER\Properties\SharedResources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>SharedResources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</None>
Replace MY_SOURCE_PROJECT_FOLDER
with the relative path of your project containing the resources and replace MY_SOURCE_PROJECT_NAMESPACE
with namespace specified in the generated file SharedResources.Designer.cs
(should be your global project's namespace)
Enjoy !
WARNING :
Sometimes VS makes an other automatic change in the **.Designer.cs* shared file which will make a failure, please ensure property ResourceManager
still points to the root shared file.
IMPORTANT :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With