How to change resource files for c # winform application without changing culture?

We have a winform application that has been under development for some time. It has several images and control colors that create a corporate experience. We have a second client who would like to receive the same product, but with different branding.

So, we have lines of code in the control.cs files, for example:

this.BackgroundImage = global::MyNameSpace.Properties.Resources.background;

It seems that resource files are the way to go, as I can just change the culture and have a separate resource file with different images.

But I don’t want to change the culture (I don’t want the display of dates, currencies, etc.) to change, and it just smells.

Can I change the resource file manually at runtime or compile time without changing the culture?

Is there a better way to achieve this result?

Also, how do you / can use resource files to set the colors of controls (e.g. change all backgrounds from black to red)?

+3
source share
2 answers

You can read in resources from a separate file that had only resources (but does not depend on the satellite globalization mechanism). You can also compile default resources with your main assembly as a fallback.

You can use Resgen.exe to create a .resources file, for example, with a .resx file, and then use ResourceManagerto read it:

//note that resourceFilename does NOT include the ".resources" extension
var rm = ResourceManager.CreateFileBasedResourceManager( resourceFilename
                                                        ,resourceDir
                                                        ,null);
this.BackgroundImage = (Image) rm.GetObject("background");
+1
source

, , - , , ,

ClientA-fr-FR
ClientB-fr-FR

, Thread.

" "

0

Source: https://habr.com/ru/post/1757941/


All Articles