EDN Admin
Well-known member
Hola,
I have a PictureBox control (in Form3) that is used is used as a drop box where the user can drag and drop one or more image files at a time. When the user imports files, the form (Form3) will close itself. Meanwhile, the application
stores file data in Form1.ListView1. The following is the code that I use for PictureBoxs
DragDrop event.
<pre class="prettyprint Form3.PictureBox1_DragDrop
Dim s As Array = e.Data.GetData(DataFormats.FileDrop)
For i = 0 To s.Length - 1
Dim f As New FileInfo(s((i)))
If (f.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
Else
If f.Extension = ".bmp" Or f.Extension = ".jpg" Or f.Extension = ".jpeg" Or f.Extension = ".png" Or f.Extension = ".tif" Or f.Extension = ".tiff" Then
Try
Dim fpath, fname, w, h, w1, h1 As String
fpath = f.FullName
fname = Path.GetFileName(fpath)
Dim bmp1 As New Bitmap(fpath)
Dim bmp2 = New Bitmap(bmp1)
bmp1.Dispose()
Dim m As Integer = 0
For i2 As Integer = 0 To Form1.ListView1.Items.Count - 1
Dim t0 As String = Form1.ListView1.Items(i2).SubItems(3).Text
If t0 = fname Then
m = m + 1
End If
Next i2
If m = 0 Then
w = CStr(bmp2.Width)
h = CStr(bmp2.Height)
w1 = CStr(Height80(bmp2, bmp2.Width, bmp2.Height))
h1 = "80"
Form1.ListView1.Items.Add(New ListViewItem(New String() {fpath, w, h, fname, w1, h1, "1"}))
k = k + 1
End If
Catch ex As FileNotFoundException
Catch ex As FileLoadException
Catch ex As Exception
End Try
Else Unsupported format
End If
End If
Next i[/code]
<br/>
Everything works as expected except that files appear locked. So if I try to displace any of the files used with the drop box even after Form3 is closed, Ill get a warning that says that the file is open in vshost.exe. I have no idea why they
are locked. If I use the code with OpenFileDialog , the file wont remain locked because of the
Dispose line. Ive searched here and there for a clue with no vain.
Any idea?
Muchas gracias,
Onion Ring
<
Onion is a recent refuge from Mac OS X and hates Mac App Store. System: Windows 7 x64
<br/>
<br/>
View the full article
I have a PictureBox control (in Form3) that is used is used as a drop box where the user can drag and drop one or more image files at a time. When the user imports files, the form (Form3) will close itself. Meanwhile, the application
stores file data in Form1.ListView1. The following is the code that I use for PictureBoxs
DragDrop event.
<pre class="prettyprint Form3.PictureBox1_DragDrop
Dim s As Array = e.Data.GetData(DataFormats.FileDrop)
For i = 0 To s.Length - 1
Dim f As New FileInfo(s((i)))
If (f.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
Else
If f.Extension = ".bmp" Or f.Extension = ".jpg" Or f.Extension = ".jpeg" Or f.Extension = ".png" Or f.Extension = ".tif" Or f.Extension = ".tiff" Then
Try
Dim fpath, fname, w, h, w1, h1 As String
fpath = f.FullName
fname = Path.GetFileName(fpath)
Dim bmp1 As New Bitmap(fpath)
Dim bmp2 = New Bitmap(bmp1)
bmp1.Dispose()
Dim m As Integer = 0
For i2 As Integer = 0 To Form1.ListView1.Items.Count - 1
Dim t0 As String = Form1.ListView1.Items(i2).SubItems(3).Text
If t0 = fname Then
m = m + 1
End If
Next i2
If m = 0 Then
w = CStr(bmp2.Width)
h = CStr(bmp2.Height)
w1 = CStr(Height80(bmp2, bmp2.Width, bmp2.Height))
h1 = "80"
Form1.ListView1.Items.Add(New ListViewItem(New String() {fpath, w, h, fname, w1, h1, "1"}))
k = k + 1
End If
Catch ex As FileNotFoundException
Catch ex As FileLoadException
Catch ex As Exception
End Try
Else Unsupported format
End If
End If
Next i[/code]
<br/>
Everything works as expected except that files appear locked. So if I try to displace any of the files used with the drop box even after Form3 is closed, Ill get a warning that says that the file is open in vshost.exe. I have no idea why they
are locked. If I use the code with OpenFileDialog , the file wont remain locked because of the
Dispose line. Ive searched here and there for a clue with no vain.
Any idea?
Muchas gracias,
Onion Ring
<
Onion is a recent refuge from Mac OS X and hates Mac App Store. System: Windows 7 x64
<br/>
<br/>
View the full article