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

No hay comentarios.: