Dragging pictures in PictureBox in. Net

Source: Internet
Author: User

Dragging pictures in PictureBox in. Net
First put a PictureBox on the form and specify a picture to display
Define a series of variables to handle picture dragging
' Handle picture drag
Private M_leftx as Integer
Private M_lefty as Integer
Dim M_mouseposx as Integer
Dim M_mouseposy as Integer
Dim M_driftx as Integer
Dim M_drifty as Integer
and assigns an initial value, which can be done when the form is initialized
ME.M_LEFTX = me.picturebox1.location.x
Me.m_lefty = ME.PICTUREBOX1.LOCATION.Y
Define events to handle mouse clicks
' When the mouse is pressed, turn the mouse into a hand and record the position of the current mouse
Private Sub Picturebox1_mousedown (ByVal sender as Object, ByVal e as System.Windows.Forms.MouseEventArgs) Handles picture Box1.mousedown
Me.cursor = System.Windows.Forms.Cursors.Hand
M_MOUSEPOSX = e.x
M_mouseposy = E.y
End Sub
Define events to handle mouse lift
' Handles the mouse button to raise the event, according to the mouse when the mouse clicks the position which saves, and the current mouse position, calculates the mouse movement offset, borrows this to call moves the picture the function, moves the picture
Private Sub Picturebox1_mouseup (ByVal sender as Object, ByVal e as System.Windows.Forms.MouseEventArgs) Handles Picturebo X1. MouseUp

M_DRIFTX = m_mouseposx-e.x

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.