如何将 Resx 文件与 Visual Studio 2010 中的类关联
如何在 Visual Studio 中将 resx 文件关联/“绑定”到类文件? 例如,当创建一个新的 Windows 窗体时,会自动将一个 resx 文件与其关联。
我问这个是因为以下代码无法为我拥有的另一个 .cs 文件打开正确的资源文件:
ComponentResourceManager manager = new ComponentResourceManager(typeof(MyClass));
然而,这段代码对于上面的 frmLogin 来说效果很好。
构造函数的 MSDN 文档:
创建一个ComponentResourceManager 查找卫星资源 基于信息的组件 指定的类型。
How do I associate/"bind" an resx file to a class file in Visual Studio?
For example, when a new windows form is created, an resx file is automatically associated with it.
I am asking this as the following code doesn't open the right resource file for another .cs file I have:
ComponentResourceManager manager = new ComponentResourceManager(typeof(MyClass));
This code works fine for frmLogin from above however.
The MSDN documentation for the constructor:
Creates a ComponentResourceManager
that looks up resources in satellite
assemblies based on information from
the specified Type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
表单具有关联的 .resx 文件是特定于表单的实现细节。否则,您无法将任意类与 .resx 文件关联。我假设您实际上想在这里使用 ResourceManager。
请注意,已经通过 Properties.Resources 内置了一个,使您可以访问添加到“项目 + 属性”、“资源”选项卡中的资源。
That a form has an associated .resx file is an implementation detail that's specific to forms. You cannot otherwise associate an arbitrary class with a .resx file. I assume that you actually want to use a ResourceManager here.
Do note that there's one already built-in through Properties.Resources, giving you access to resources that you added to Project + Properties, Resources tab.
如果您通过将现有文件添加到项目中而丢失了这种缩进,则可以通过使用项目文件中的“DependentUpon”节点来恢复文件的缩进,尽管我尚未对所有文件类型进行尝试。
该技术在代码咆哮中有更详细的描述:嵌套在 Visual Studio 中使用“DependentUpon”文件
自从发现上面的文章以来,我发现了一个现有的答案,但是由于问题的表述方式如此不同,我保留这个答案。
Should you have lost this indenting by adding existing files to a project, you can restore the indenting for files, though I have not tried it for all file types, by using the 'DependentUpon' node in the project file.
The technique is described in more detail at Code rant: Nested files with 'DependentUpon' in Visual Studio
I found an existing answer on SO since discovering the article above, but as the question is formulated so differently I'm keeping this answer in place.