miércoles, 17 de octubre de 2012

drag and drop Archivo a Textbox



Propiedades del TextBox

   Me.TextBox1.AllowDrop = True

Código:


Imports System.IO

Public Class Form1

   Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
      If e.Data.GetDataPresent(DataFormats.FileDrop) Then
         Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
         For Each fileLoc As String In filePaths
            If File.Exists(fileLoc) Then
               TextBox1.Text = Path.GetFullPath(fileLoc)
            End If
         Next
      End If
   End Sub

   Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
      If e.Data.GetDataPresent(DataFormats.FileDrop) Then
         e.Effect = DragDropEffects.Copy
      Else
         e.Effect = DragDropEffects.None
      End If
   End Sub

End Class

No hay comentarios.: