Mega Code Archive

 
Categories / VB.Net / GUI
 

Drag and Drop Explorer

Imports System.Windows.Forms Public Class Form1     Inherits System.Windows.Forms.Form     Public Sub New()         MyBase.New()         InitializeComponent()     End Sub     Friend WithEvents ListView1 As System.Windows.Forms.ListView     Friend WithEvents Label1 As System.Windows.Forms.Label     Friend WithEvents ImageList1 As System.Windows.Forms.ImageList     Friend WithEvents Filename As System.Windows.Forms.ColumnHeader     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))         Me.ListView1 = New System.Windows.Forms.ListView()         Me.Label1 = New System.Windows.Forms.Label()         Me.ImageList1 = New System.Windows.Forms.ImageList()         Me.Filename = New System.Windows.Forms.ColumnHeader()         Me.SuspendLayout()         '         'ListView1         '         Me.ListView1.AllowDrop = True         Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.Filename})         Me.ListView1.Location = New System.Drawing.Point(16, 32)         Me.ListView1.Name = "ListView1"         Me.ListView1.Size = New System.Drawing.Size(368, 296)         Me.ListView1.SmallImageList = Me.ImageList1         Me.ListView1.TabIndex = 0         Me.ListView1.View = System.Windows.Forms.View.Details         '         Me.Label1.Location = New System.Drawing.Point(16, 8)         Me.Label1.Name = "Label1"         Me.Label1.Size = New System.Drawing.Size(360, 16)         Me.Label1.TabIndex = 1         Me.Label1.Text = "Drag and drop files from Explorer onto this ListView control:"         '         Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit         Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)         Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)         Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent         '         Me.Filename.Text = "File / folder"         Me.Filename.Width = 300         '         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)         Me.ClientSize = New System.Drawing.Size(400, 342)         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.ListView1})         Me.Name = "Form1"         Me.Text = "Drag and Drop from Windows Explorer"         Me.ResumeLayout(False)     End Sub     Private Sub ListView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragOver         If e.Data.GetDataPresent(DataFormats.FileDrop) Then             e.Effect = DragDropEffects.Copy         End If     End Sub     Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop         If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then             Dim strFiles() As String = e.Data.GetData(DataFormats.FileDrop)             Dim intCount As Integer             For intCount = 0 To strFiles.Length                 ListView1.Items.Add(strFiles(intCount), 0)             Next         End If     End Sub End Class