Imports System.Runtime.InteropServices 'For APIs
Imports System.IO 'Import System.IO For File Operations
Imports Microsoft.Win32 'The Registry stuff
Imports System.Windows.Forms.Application
Imports System
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListView1.AllowDrop = True
Me.ListView1.Columns.Add("File name")
Me.ListView1.SmallImageList = Me.ImageList1
Me.ListView1.View = View.Details
End Sub
Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop
'The data can only be dropped if it is a file list and it can be copied.
If e.Data.GetDataPresent("FileDrop") AndAlso _
(e.AllowedEffect And DragDropEffects.Copy) = DragDropEffects.Copy Then
'Get the data.
Dim filePaths As String() = DirectCast(e.Data.GetData("FileDrop"), String())
Dim upperBound As Integer = filePaths.GetUpperBound(0)
Dim items(upperBound) As ListViewItem
Dim filePath As String
'For each file in the list, create an item, complete with icon.
For index As Integer = 0 To upperBound
filePath = filePaths(index)
If Not Me.ImageList1.Images.Keys.Contains(filePath) Then
'This is the first time this file has been added so add its icon too.
Me.ImageList1.Images.Add(filePath, _
Icon.ExtractAssociatedIcon(filePath))
End If
items(index) = New ListViewItem(filePath, filePath)
Next
'Add the items to the ListView.
Me.ListView1.Items.AddRange(items)
End If
End Sub
Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
If e.Data.GetDataPresent("FileDrop") AndAlso _
(e.AllowedEffect And DragDropEffects.Copy) = DragDropEffects.Copy Then
'A file list is being dragged and it can be copied so provide feedback to the user.
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop
If Not My.Computer.FileSystem.DirectoryExists(Desktop & "\Unused Desktop Icon and Documents") Then
My.Computer.FileSystem.CreateDirectory(Desktop & "\Unused Desktop Icon and Documents")
End If
With Me.ListView1
For i As Integer = 0 To .CheckedItems.Count - 1
.Items.Remove(.CheckedItems(0))
Next i
End With
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop
If Not My.Computer.FileSystem.DirectoryExists(Desktop & "\backup storage") Then
My.Computer.FileSystem.CreateDirectory(Desktop & "\backup storage")
End If
With Me.ListView1
For i As Integer = 0 To .CheckedItems.Count - 1
.Items.Remove(.CheckedItems(0))
Next i
End With
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
For Each lvitem As ListViewItem In Me.ListView1.Items
If lvitem.Checked = False Then
lvitem.Checked = True
Else
lvitem.Checked = False
End If
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End Sub
End Class