0

这就是我所拥有的:一个带有 PictureBox 和 TrackBar 的简单 Windows 窗体应用程序。所以这就是我想要的:我希望能够将任何 jpeg 或 png 放入资源中并通过 引用它们,TrackBar1.Value而不必在字符串数组中一一指定它们的名称。

我看到的唯一方法是以某种方式引用包含资源中内容的数组。

看,我想出了这段代码,效果很好:

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

但是那样,我必须手动在字符串数组中键入名称...

非常感谢。

4

1 回答 1

0

像这样的东西应该工作

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
于 2014-10-02T17:23:00.847 回答