Mouse drag process

Source: Internet
Author: User

When you click the mouse

'Get the object to be dragged. Modify it here.

Dim item As Rectangle = sender
'Get the current cursor position
MouseVerticalPosition = e. GetPosition (Nothing). Y
MouseHorizontalPosition = e. GetPosition (Nothing). X
'Enable Mouse capture
IsMouseCaptured = True
'Set Mouse capture to UIElement
Item. CaptureMouse ()

 

Move the mouse

 

When you release the mouse

 

 

Private Sub RectAClick (ByVal sender As System. Object, ByVal e As System. Windows. Input. MouseButtonEventArgs)
'If it has already been processed, it will not be processed
E. Handled = True
Me. statusTextBlock. Text = "x: y =" & e. GetPosition (Me. ParentCanvas). ToString & ". RectA is Click, not BubbleUp"
End Sub

Dim isMouseCaptured As Boolean
Dim mouseVerticalPosition As Double
Dim mouseHorizontalPosition As Double

Private Sub Rect_Handle_MouseDown (ByVal sender As System. Object, ByVal e As System. Windows. Input. MouseButtonEventArgs)
Dim item As Rectangle = sender
'Get the current cursor position
MouseVerticalPosition = e. GetPosition (Nothing). Y
MouseHorizontalPosition = e. GetPosition (Nothing). X
'Enable Mouse capture
IsMouseCaptured = True
'Set Mouse capture to UIElement
Item. CaptureMouse ()
End Sub

Private Sub Rect_Handle_MouseMove (ByVal sender As System. Object, ByVal e As System. Windows. Input. MouseEventArgs)
Dim item As Rectangle = sender
If (isMouseCaptured) Then
'Current location of the computing object
Dim deltaV As Double = e. GetPosition (Nothing). Y-mouseVerticalPosition
Dim deltaH As Double = e. GetPosition (Nothing). X-mouseHorizontalPosition
Dim newTop As Double = deltaV + item. GetValue (Canvas. TopProperty)
Dim newLeft As Double = deltaH + item. GetValue (Canvas. LeftProperty)

'Set the new object location
Item. SetValue (Canvas. TopProperty, newTop)
Item. SetValue (Canvas. LeftProperty, newLeft)

'Update position global variables.
MouseVerticalPosition = e. GetPosition (Nothing). Y
MouseHorizontalPosition = e. GetPosition (Nothing). X
End If

End Sub

Private Sub Rect_Handle_MouseUp (ByVal sender As System. Object, ByVal e As System. Windows. Input. MouseButtonEventArgs)
Dim item As Rectangle = sender
IsMouseCaptured = False
Item. ReleaseMouseCapture ()
MouseVerticalPosition =-1
MouseHorizontalPosition =-1
End Sub

 

 

 

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.