By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

List of images

P: n/a
Hi

I would like to allow users to add images to a list on form by browsing and
selecting images from the disk. What would be a good mechanism to do this?

Thanks

Regards
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi John,

Let your users do what they already know - drag and drop a selection of
files from Windows Explorer.

It makes it easy for you too:

<code>
'================================================= ==================
Private Sub ListBox1_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragEnter

If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub

'================================================= ==================
Private Sub ListBox1_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragDrop

'Note that the '.' at each end is required.
Const sAllowedExtensions As String = ".jpg.bmp.gif."

Dim asFiles() As String
Dim sFileName As String
Dim S As String

'Get the list of files that have been dropped.
asFiles = CType (e.Data.GetData("FileDrop", False), String())

For Each sFileName In asFiles
'Extract the extension.
Dim PosOfExt As Integer = ("." & sFileName).LastIndexOf (".")
Dim sExt As String = sFileName.Substring (PosOfExt)

'Only allow image files.
If sAllowedExtensions.IndexOf ("." & sExt & ".") >= 0 Then
S = S & sFileName & vbCrLf
End If
Next
MsgBox (S)
End Sub

</code>

Don't forget to set AllowDrop to True for your ListBox.

Regards,
Fergus
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.