Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to move a Panel Control by click and drag 2

Status
Not open for further replies.

GPerk

Programmer
Jul 6, 2002
161
US
I have a Panel control in front of a Picturebox.
I want to be able to move the panel around during runtime so that it doesn't obscure the part of the picture I'm working on.
How can I do this so that the panel moves smoothly as I move the mouse with button 1 pressed?
 
Try this:
Code:
Public Class Form1

    Private Panel1Captured As Boolean
    Private Panel1Grabbed As Point

    Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
        Panel1Captured = True
        Panel1Grabbed = e.Location
    End Sub

    Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
        If (Panel1Captured) Then Panel1.Location = Panel1.Location + e.Location - Panel1Grabbed
    End Sub

    Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
        Panel1Captured = False
    End Sub

End Class
 
Dave,
Thank you very much! A star for you.
Your solution is clear and clean and the movement is very smooth.
 
Thanks Dave. Star from me as well. Clean and concise and works quite well.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top