如何在不改变文化的情况下更改 ac# winform 应用程序的资源文件?

发布于 2024-09-12 22:41:34 字数 430 浏览 3 评论 0原文

我们有一个已经开发了一段时间的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚然 2024-09-19 22:41:34

您可以从仅包含资源的单独文件中读取资源(但不依赖于全球化卫星组装机制)。您还可以使用主程序集编译默认资源作为后备。

您可以使用 Resgen.exe 创建例如,来自 .resx 文件的 .resources 文件,然后使用 ResourceManager 读取它:

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

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");
柠檬色的秋千 2024-09-19 22:41:34

您可以考虑的一个选项是创建自定义区域性,例如您可以创建一个名为

ClientA-fr-FR
ClientB-fr-FR

“您为每个区域性创建资源”的区域性,并且您应该能够适当地设置线程区域性。

这是一个链接“如何:创建自定义区域性”

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文