Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
Sir Pereira

Controlos dinâmicos amovíveis

Recommended Posts

jnetic

Não conheço nenhuma propriedade que o permita.

Se quiseres implementar código, basta googlar e encontrarás milhares de snippets. Por exemplo:

Private Sub btnMove_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseDown
    If e.Button = MouseButtons.Left Then
        Dragging = True
        mousex = -e.X
        mousey = -e.Y
        Dim clipleft As Integer = Me.PointToClient(MousePosition).X - btnMove.Location.X
        Dim cliptop As Integer = Me.PointToClient(MousePosition).Y - btnMove.Location.Y
        Dim clipwidth As Integer = Me.ClientSize.Width - (btnMove.Width - clipleft)
        Dim clipheight As Integer = Me.ClientSize.Height - (btnMove.Height - cliptop)
        Cursor.Clip = Me.RectangleToScreen(New Rectangle(clipleft, cliptop, clipwidth, clipheight))
        btnMove.Invalidate()
    End If
End Sub

Private Sub btnMove_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseMove
    If Dragging Then
         'move control to new position
        Dim MPosition As New Point()
        MPosition = Me.PointToClient(MousePosition)
        MPosition.Offset(mousex, mousey)
        'ensure control cannot leave container
        btnMove.Location = MPosition
    End If
End Sub

Private Sub btnMove_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseUp
     If Dragging Then
        'end the dragging
        Dragging = False
        Cursor.Clip = Nothing
        btnMove.Invalidate()
    End If
End Sub 

Não testei, apenas copiei daqui: http://www.developerfusion.com/article/2692/drag-and-drop-in-windows-forms-a-primer/5/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.