【问题标题】:Get all resources in array获取数组中的所有资源
【发布时间】:2011-08-02 12:29:17
【问题描述】:

我有一个 VB.NET 程序,其中包含大量图像资源。有没有办法获取数组中的所有资源,以便我可以在 for 循环中访问它们?

我目前必须这样做:

 images(1) = My.Resources.image1
 images(2) = My.Resources.image2
 '...
 images(80) = My.Resources.image80

【问题讨论】:

标签: .net vb.net visual-studio-2010


【解决方案1】:

可能是这样的:

Dim ResourceSet As Resources.ResourceSet = My.Resources.ResourceManager.GetResourceSet(Globalization.CultureInfo.CurrentCulture, True, True)
For Each Dict As DictionaryEntry In ResourceSet.OfType(Of Object)()
    If TypeOf (Dict.Value) Is Drawing.Image Then
        Debug.WriteLine(Dict.Key) 'outputting resource name
       (Do stuff here)
    End If
Next

看来关键是资源的名称。

【讨论】:

  • 它说: System.ArgumentNullException 未处理 Message=Value 不能为空。参数名称:来源
  • 对不起,在实际测试后在上面编辑。必须有比 OfType(of Object) 更好的方法,但我似乎看不到它。此外,我必须根据我在其中测试过的应用程序更改 GetResourceSet 中的参数......所以您可能需要调整这些参数。 msdn.microsoft.com/en-US/library/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-11
  • 1970-01-01
  • 2020-01-27
  • 2013-08-24
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
相关资源
最近更新 更多