Advertisement
smashapps

Adding images to a listbox

Dec 27th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.IO
  2.  
  3. Public Class frmInterface
  4.  
  5.     Private Sub frmInterface_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  6.         Me.BackColor = Color.FromArgb(0, 142, 214)
  7.         PopulateImagesList()
  8.     End Sub
  9.  
  10.     Public Sub PopulateImagesList()
  11.         Try
  12.             Dim di As New DirectoryInfo(Application.StartupPath & "\example\")
  13.             Dim fiArr As FileInfo() = di.GetFiles()
  14.             Dim fri As FileInfo
  15.             For Each fri In fiArr
  16.                 If fri.Extension = ".png" Then
  17.                     Dim s As String
  18.                     s = fri.Name
  19.                     lstImages.Items.Add(s.Substring(0, s.Length - 4))
  20.                 End If
  21.             Next fri
  22.         Catch ex As Exception
  23.  
  24.         End Try
  25.     End Sub
  26.  
  27.     Private Sub lstImages_SelectedValueChanged(sender As Object, e As EventArgs) Handles lstImages.SelectedValueChanged
  28.         Dim img As String = lstImages.SelectedItem.ToString
  29.         Try
  30.             pctrPreview.BackgroundImage = Image.FromFile(Application.StartupPath & "\example\" & img & ".png")
  31.         Catch ex As Exception
  32.  
  33.         End Try
  34.     End Sub
  35. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement