Este ejemplo permite mover los controles de un formulario en tiempo de ejecución.
Paso 1: Declaramos variables
Private dragging As Boolean
Private posicionX, posicionY As Integer
Paso 2: Capturamos la posición del control Panel mediante las variables
Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
dragging = True
posicionX = e.X
posicionY = e.Y
End Sub
Paso 3: Programar MouseMove
Private Sub Panel1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If dragging = True Then
Panel1.Location = New Point(Panel1.Location.X + e.X -
posicionX, Panel1.Location.Y + e.Y - posicionY)
Me.Refresh()
End If
End Sub
Paso 4: Programar MouseUp
Private Sub Panel1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
dragging = False
End Sub
No hay comentarios:
Publicar un comentario