简体   繁体   English

如何创建资源列表,以便可以使用索引引用元素? -VB.NET

[英]How can i create a list of my resources so i can refer to an element using index? - VB.NET

Here's what i have : a simple windows forms application with a PictureBox and a TrackBar. 这就是我所拥有的:一个带有PictureBox和TrackBar的简单Windows窗体应用程序。 So here's what i want : i want to be able to put any jpeg or png in the resources and refer to them by the TrackBar1.Value without having to specify their names 1 by 1 in a string array. 所以这就是我想要的:我希望能够在资源中放入任何jpeg或png,并通过TrackBar1.Value引用它们,而不必在字符串数组中以1到1的方式指定它们的名称。

The only way i see is to refer somehow to an array containing what's in the Resources. 我看到的唯一方法是以某种方式引用包含参考资料中的内容的数组。

See, i've came up with this code wich works fine : 看,我想出了这个代码,效果很好:

Dim list() As String = {"2013-04-03 22.53.41", "2013-04-10 12.43.47", 
       "2013-05-24 01.44.00", "2013-05-25 11.49.51", "2013-05-25 16.37.10", 
       "2013-06-06 23.22.46", "2013-07-04 19.59.29", "2013-09-14 12.31.09", 
       "2013-11-20 20.28.07", "2014-01-03 15.30.21", "2014-01-24 20.12.16", 
       "2014-03-18 19.03.21", "2014-05-27 20.40.07", "2014-07-21 19.46.37", 
       "2014-08-05 14.05.09", "2014-09-01 17.41.46", "2014-09-01 22.13.08", 
       "2014-09-14 17.49.31", "2014-09-15 17.27.55", "2015-05-30 12.45.58"} 
      ' These are 19 iPhone pictures

Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
    picbox.Image = CType(My.Resources.ResourceManager.GetObject(list(TrackBar1.Value)), Image)
End Sub

But that way, i have to manually type the names in a string array... 但是那样,我必须在字符串数组中手动​​键入名称。

Thanks a lot. 非常感谢。

Something like this should work 这样的事情应该工作

Private _resourceNames As String()
Public ReadOnly Property ResourceNames As String()
    Get
        If _resourceNames Is Nothing Then
            Dim thisExe As System.Reflection.Assembly
            thisExe = Me.GetType.Assembly

            System.Reflection.Assembly.GetExecutingAssembly()
            _resourceNames = thisExe.GetManifestResourceNames()
        End If
        Return _resourceNames
    End Get

End Property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM