Be seen. Boost your question’s priority for more expert views and faster solutions
Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
ShapeContainerMouseMoveEventHandler(Nothing, e)
End Sub
Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
ShapeContainerMouseDownEventHandler(Nothing, e)
End Sub
Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
ShapeContainerMouseMoveEventHandler(Nothing, e)
End Sub
Public Sub ShapeContainerMouseMoveEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
For Each ls As LineShape In Me.SC.Shapes 'Lines
If MouseIsNearBy(ls.EndPoint) = True Then
SelectedLS = ls
SelectedLS.BorderColor = Color.Red
' Me.Refresh()
NearLineEndPoint = True
ls.Cursor = Cursors.Hand
End If
If MouseIsNearBy(ls.EndPoint) = False Then
ls.BorderColor = Color.Black
' Me.Refresh()
NearLineEndPoint = False
ls.Cursor = Cursors.Default
End If
Next
If NearLineEndPoint = True Then
If (dragStartPoint) Then
SelectedLS.StartPoint = New Point(oldStartPoint.X + e.X - oldMouseX, oldStartPoint.Y + e.Y - oldMouseY)
End If
If (dragEndPoint) Then
For Each c As Control In Me.Controls
If TypeOf (c) Is PictureBox And dragEndPoint Then
If e.X > c.Left AndAlso e.X < c.Right AndAlso e.Y < c.Bottom AndAlso e.Y > c.Top Then
dropline = True
droplinex = c.Left + 2
dropliney = c.Top + (c.Height / 2) - 12
deltaxinsidebutton = e.X - droplinex
deltayinsidebutton = e.Y - dropliney
oldEndPoint.X = droplinex - e.X + oldMouseX
oldEndPoint.Y = dropliney - e.Y + oldMouseY
SelectedLS.EndPoint = New Point(droplinex, dropliney)
droplineobjectname = c.Name
dropcontrol = c
Exit For
Else
If dropline = True Then
oldMouseX = (e.X - droplinex)
oldMouseY = (e.Y - dropliney)
End If
dropline = False
SelectedLS.EndPoint = New Point(oldEndPoint.X + e.X - oldMouseX + deltaxinsidebutton, oldEndPoint.Y + e.Y - oldMouseY + deltayinsidebutton)
End If
End If
Next
End If
End If
End Sub
Private Sub ShapeContainerMouseDownEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If NearLineEndPoint = False Then Exit Sub
If MouseIsNearBy(SelectedLS.EndPoint) Then '(SelectedLS.HitTest(MousePosition.X, MousePosition.Y)) Then
oldMouseX = e.X
oldMouseY = e.Y
oldStartPoint = SelectedLS.StartPoint
oldEndPoint = SelectedLS.EndPoint
' dragStartPoint = MouseIsNearBy(oldStartPoint)
dragEndPoint = MouseIsNearBy(oldEndPoint)
If (Not dragStartPoint AndAlso Not dragEndPoint) Then
'If not drag either end, then drag both.
' dragStartPoint = True
' dragEndPoint = True
End If
SelectedLS.SelectionColor = Color.Transparent
End If
End Sub
Public Sub ShapeContainerMouseMoveEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Select Case e.Button
Case Windows.Forms.MouseButtons.None
SelectedLS = Nothing
NearLineEndPoint = False
For Each ls As LineShape In Me.SC.Shapes 'Lines
If Not NearLineEndPoint AndAlso MouseIsNearBy(ls.EndPoint) Then
SelectedLS = ls
SelectedLS.BorderColor = Color.Red
NearLineEndPoint = True
ls.Cursor = Cursors.Hand
Else
ls.BorderColor = Color.Black
ls.Cursor = Cursors.Default
End If
Next
Me.Refresh()
Case Windows.Forms.MouseButtons.Left
If NearLineEndPoint = True Then
If (dragStartPoint) Then
SelectedLS.StartPoint = New Point(oldStartPoint.X + e.X - oldMouseX, oldStartPoint.Y + e.Y - oldMouseY)
End If
If (dragEndPoint) Then
For Each c As Control In Me.Controls
If TypeOf (c) Is PictureBox And dragEndPoint Then
If e.X > c.Left AndAlso e.X < c.Right AndAlso e.Y < c.Bottom AndAlso e.Y > c.Top Then
dropline = True
droplinex = c.Left + 2
dropliney = c.Top + (c.Height / 2) - 12
deltaxinsidebutton = e.X - droplinex
deltayinsidebutton = e.Y - dropliney
oldEndPoint.X = droplinex - e.X + oldMouseX
oldEndPoint.Y = dropliney - e.Y + oldMouseY
SelectedLS.EndPoint = New Point(droplinex, dropliney)
droplineobjectname = c.Name
dropcontrol = c
Exit For
Else
If dropline = True Then
oldMouseX = (e.X - droplinex)
oldMouseY = (e.Y - dropliney)
End If
dropline = False
SelectedLS.EndPoint = New Point(oldEndPoint.X + e.X - oldMouseX + deltaxinsidebutton, oldEndPoint.Y + e.Y - oldMouseY + deltayinsidebutton)
End If
End If
Next
End If
End If
End Select
End Sub
SelectedLS = Nothing
NearLineEndPoint = False
For Each ls As LineShape In Me.SC.Shapes 'Lines
If Not NearLineEndPoint AndAlso MouseIsNearBy(ls.EndPoint) Then
SelectedLS = ls
SelectedLS.BorderColor = Color.Red
NearLineEndPoint = True
ls.Cursor = Cursors.Hand
Else
ls.BorderColor = Color.Black
ls.Cursor = Cursors.Default
End If
Next
Me.Cursor = Cursors.Hand
This way, as soon as the mouse cursor is near a lineshape endpoint, the mouse cursor will change. The way its listed above, the cursor is really for the lineshape and not the mouse cursor. The idea is that the line color and the mouse cursor should change when the user's mouse cursor is near the endpoint. As soon as this occurs, the user can then drag the lineshape's endpoint.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.