bjwade62 Posted October 20, 2006 Posted October 20, 2006 I have a picturebox control that I want to create a pan movement that follows the cursor's movement. I need some help getting started. I've looked at mouse down/up events along with the cursor.location property but can't seem to get it working. Any ideas? Thanks Quote
techmanbd Posted October 20, 2006 Posted October 20, 2006 So I understand, you want to know the postion of the cursor when over the picturebox while not clicking correct? If so check this out. Then hit F1 key to get the help for MouseHover Private Sub panel1_MouseHover(sender As Object, e As System.EventArgs) Handles panel1.MouseHover 'code here for events you want, as in location of the cursor over the picture box. End Sub Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
bjwade62 Posted October 20, 2006 Author Posted October 20, 2006 Thanks for the reply. What I'm looking to do is change an image's location base on the cursor's location. Kind of a grap and move thing. So I understand, you want to know the postion of the cursor when over the picturebox while not clicking correct? If so check this out. Then hit F1 key to get the help for MouseHover Private Sub panel1_MouseHover(sender As Object, e As System.EventArgs) Handles panel1.MouseHover 'code here for events you want, as in location of the cursor over the picture box. End Sub Quote
Leaders snarfblam Posted October 20, 2006 Leaders Posted October 20, 2006 A real quick and easy way to do this is to place a picture box within a panel. The picture box should size to fit the image. At that point all you have to do is handle mouse events. On MouseDown you want to record the mouse position, and on MouseMove you want to examine the difference between the original position and the new position and move the picture box that distance. This is the jist of it. You will probably want to take certain things into consideration, such as which buttons are being clicked. Dim DragX As Integer Dim DragY As Integer 'Grab the position on mouse down Private Sub imgPicture_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles imgPicture.MouseDown DragX = e.X DragY = e.Y End Sub ' Move the image based on mouse movements Private Sub imgPicture_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles imgPicture.MouseMove If (e.Button <> MouseButtons.None) Then Dim Location As Point = imgPicture.Location Location.X += e.X - DragX Location.Y += e.Y - DragY imgPicture.Location = Location End If End Sub You also might want to see if there is a way to double buffer the picturebox/container for smoother scrolling. (Try subclassing the PictureBox class and using the SetStyle method to set AllDrawingInWmPaint and DoubleBuffering to true in the constructor. Also consider scrapping the PictureBox-in-a-Panel idea and do your own drawing.) If you can't get it up and running to your satisfaction I'll be glad to offer more assistance. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.