martes, 30 de octubre de 2012

Mover Panel (Drag and Drop)



Public Class Form1
   Private FlgMover_01 As Boolean = False
   Private Ubicacion_01 As New Point

   Private FlgMover_02 As Boolean = False
   Private Ubicacion_02 As New Point

   Private Sub panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
      FlgMover_01 = True
      Ubicacion_01 = New Point(e.X, e.Y)
      Me.Cursor = Cursors.SizeAll
   End Sub

   Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
      If FlgMover_01 = True Then
         Panel1.Location = New Point(Panel1.Location.X + e.X - Ubicacion_01.X, Panel1.Location.Y + e.Y - Ubicacion_01.Y)
      End If
   End Sub

   Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
      FlgMover_01 = False
      Me.Cursor = Cursors.Default
   End Sub

   Private Sub Panel2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseDown
      FlgMover_02 = True
      Ubicacion_02 = New Point(e.X, e.Y)
      Me.Cursor = Cursors.SizeAll
   End Sub

   Private Sub Panel2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseMove
      If FlgMover_02 = True Then
         Panel2.Location = New Point(Panel2.Location.X + e.X - Ubicacion_02.X, Panel2.Location.Y + e.Y - Ubicacion_02.Y)
      End If
   End Sub

   Private Sub Panel2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseUp
      FlgMover_02 = False
      Me.Cursor = Cursors.Default
   End Sub

End Class

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