如何在不改变文化的情况下更改 ac# winform 应用程序的资源文件?
我们有一个已经开发了一段时间的 winform 应用程序。它具有多种图像和控制颜色,可创造品牌体验。我们有第二位客户想要相同的产品,但品牌不同。
因此,我们在控件 Designer.cs 文件中包含如下代码行:
this.BackgroundImage = global::MyNameSpace.Properties.Resources.background;
看来资源文件是可行的方法,因为我可以简单地更改区域性并拥有包含不同图像的单独资源文件。
但我不想改变文化(我不想改变日期、货币等的显示),它只是闻起来很臭。
我可以在运行时或编译时手动更改资源文件,而无需更改区域性吗?
有没有更好的方法来实现这个结果?
另外,您如何/可以使用资源文件来设置控件颜色(例如将所有背景从黑色更改为红色)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从仅包含资源的单独文件中读取资源(但不依赖于全球化卫星组装机制)。您还可以使用主程序集编译默认资源作为后备。
您可以使用 Resgen.exe 创建例如,来自 .resx 文件的 .resources 文件,然后使用
ResourceManager
读取它: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:您可以考虑的一个选项是创建自定义区域性,例如您可以创建一个名为
“您为每个区域性创建资源”的区域性,并且您应该能够适当地设置线程区域性。
这是一个链接“如何:创建自定义区域性”
One option you could consider is to create a custom culture, so for example you could create a culture called
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"