如何在Visual Basic中获取资源文件值?

| 我是Visual Basic的新手,在访问项目的资源文件时遇到问题。
Dim rm As Resources.ResourceManager = New Resources.ResourceManager(\"MyProjectName.My.Resources.Resources\", [Assembly].GetExecutingAssembly())
Dim myValue = rm.GetString(lookUpKey) \'boom Object reference not set to an instance of an object.
我认为问题出在字符串\“ MyProjectName.My.Resources.Resources \”。 将字符串移到自己的资源文件中会更好吗?     
已邀请:
我认为这类似于:
my.Resource.whateverhere
这不是您要找的资源吗?     
尝试使用
ResourceManager(\"MyProjectName.Resources\", ...)
,否则,如果它是应用程序资源,则可以仅使用
My.Resources.HD
(请参阅此处:My.Resources对象) 要么 打开Reflector,在其中加载程序集,转到资源,出现资源列表,搜索一个包含
\'HD\'
的名称,复制名称(类似于MyProjectName.Resources.resources),删除最后一个
.resources
并尝试使用它。     
尝试
 Global.<MyNamespace>.My.Resources.<ResourceStringName>
访问资源字符串     
请参阅MSDN文章“使用ResourceManager类检索资源”来命名命名:
Dim myManager As New _
   System.Resources.ResourceManager(\"ResourceNamespace.myResources\", _
   myAssembly)
    
在将.resx文件移至其自己的项目并从主项目引用该项目之前,我无法访问资源文件。我还必须在该项目中创建一个虚拟类,以便将其编译为DLL文件。 访问资源文件的代码实际上位于生成的Resource.resx.vb文件中。 我可以使用以下代码访问资源文件。
\'Name of Class Library where I moved the resx file
Dim classLibraryName As String = \"ResourceProj\"
\'Name of Resource File without the .resx suffix
Dim resourceFileName As String = \"Mappings\"
\'Finding the assembly of the resx file, ResourceProjClass is a dummy class I created so that the dll would build.
Dim myAssembly As Assembly = GetType(ResourceProj.ResourceProjClass).Assembly

Dim rm As Resources.ResourceManager = Nothing
rm = New Resources.ResourceManager(classLibraryName & \".\" & resourceFileName, GetType(myAssembly)
Return rm.GetString(lookUpKey)
    
只是:
Dim loginMessage As String = Global.Resources.NameOfYourResxFile.NameOFVariable
    

要回复问题请先登录注册