level 1
贴吧用户_7KXE1GA
楼主
下面是我编的一个小程序,现在已经可以正常运行,但不是最终我想要的样子。
小小的疑问。
Public Class Form1
Private Sub ListView1_DragDrop(sender As Object, e As DragEventArgs) Handles ListView1.DragDrop
ListView1.FullRowSelect = True
ListView1.Items.Clear()
Dim droppedItems As String() = e.Data.GetData(DataFormats.FileDrop)
Dim selectedItem As String = droppedItems(0) '路径
Label1.Text = selectedItem
Dim j As Integer = My.Computer.FileSystem.GetFiles(selectedItem).Count
Dim newFilelist As String() = GetImageList(selectedItem, j) '这一句
For Each myImage In newFilelist
MsgBox(myImage)
Next
End Sub
Private Sub ListView1_DragEnter(sender As Object, e As DragEventArgs) Handles ListView1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then
e.Effect = DragDropEffects.All
End If
End Sub
'以数组形式返回文件夹下面的文件名称
Function GetImageList(ByVal imagePath As String, ByVal j As Integer) As String()
Dim i As Integer = 1
Dim newFolder() As String '和这一句
ReDim newFolder(j - 1)
For Each foundFile As String In My.Computer.FileSystem.GetFiles(imagePath)
Dim attributes As IO.FileAttributes
attributes = IO.File.GetAttributes(foundFile)
If (attributes And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then
Dim fileName As String = IO.Path.GetFileName(foundFile)
newFolder(i - 1) = fileName
i += 1
End If
Next
Return newFolder
End Function
End Class
2017年09月08日 10点09分
1
小小的疑问。
Public Class Form1
Private Sub ListView1_DragDrop(sender As Object, e As DragEventArgs) Handles ListView1.DragDrop
ListView1.FullRowSelect = True
ListView1.Items.Clear()
Dim droppedItems As String() = e.Data.GetData(DataFormats.FileDrop)
Dim selectedItem As String = droppedItems(0) '路径
Label1.Text = selectedItem
Dim j As Integer = My.Computer.FileSystem.GetFiles(selectedItem).Count
Dim newFilelist As String() = GetImageList(selectedItem, j) '这一句
For Each myImage In newFilelist
MsgBox(myImage)
Next
End Sub
Private Sub ListView1_DragEnter(sender As Object, e As DragEventArgs) Handles ListView1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then
e.Effect = DragDropEffects.All
End If
End Sub
'以数组形式返回文件夹下面的文件名称
Function GetImageList(ByVal imagePath As String, ByVal j As Integer) As String()
Dim i As Integer = 1
Dim newFolder() As String '和这一句
ReDim newFolder(j - 1)
For Each foundFile As String In My.Computer.FileSystem.GetFiles(imagePath)
Dim attributes As IO.FileAttributes
attributes = IO.File.GetAttributes(foundFile)
If (attributes And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then
Dim fileName As String = IO.Path.GetFileName(foundFile)
newFolder(i - 1) = fileName
i += 1
End If
Next
Return newFolder
End Function
End Class