How can I change resource files for a c# winform app, without changing the culture?

我的未来我决定 提交于 2019-12-10 18:53:10

问题


We have a winform app that has been in development for some time. It has several images and control colours that create a branded experience. We have a second customer who would like the same product, but with different branding.

So we have lines of code in the control designer.cs files like:

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

It seems like resource files are the way to go, as I could simply 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, currency, etc.) to be altered and it just smells.

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

Is there a better way to achieve this outcome?

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


回答1:


You can read in the resources from a separate file that just had the resources (but doesn't depend on the globalized satellite assembly mechanism). You could also compile default resources with your main assembly as a fall-back.

You can use Resgen.exe to create a .resources file from, e.g., a .resx file and then use ResourceManager to read it:

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



回答2:


One option you could consider is to create a custom culture, so for example you could create a culture called

ClientA-fr-FR
ClientB-fr-FR

The you create resources for each and you should be able to set the Thread Culture approriately.

Here is a link "How to: Create Custom Cultures"



来源:https://stackoverflow.com/questions/3402451/how-can-i-change-resource-files-for-a-c-sharp-winform-app-without-changing-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!