Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user move a line's end points with grab handles
Keywordsline, end point, drag, drawing
CategoriesGraphics
 
In the MouseDown event handler, see if the point is on one of the points. If so, save the index of the point.

In the MouseMove event handler, move the point to its new location and redraw the line.

In the MouseUp event handler, set m_GrabbedPoint = -1 to indicate that no point is selected.

 
Private Sub picCanvas_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
Dim i As Integer

    ' See if this is a point.
    m_GrabbedPoint = -1
    For i = 0 To 1
        ' See if the point is within the point.
        If Abs(X - m_X(i)) <= GRAB_WID / 2 And _
           Abs(Y - m_Y(i)) < GRAB_WID / 2 _
        Then
            ' This is the point.
            m_GrabbedPoint = i
            Exit For
        End If
    Next i
End Sub

Private Sub picCanvas_MouseMove(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    ' Do nothing if no point is grabbed.
    If m_GrabbedPoint < 0 Then Exit Sub

    ' Save the new coordinates.
    m_X(m_GrabbedPoint) = X
    m_Y(m_GrabbedPoint) = Y

    ' Draw the moved point.
    DrawLines
End Sub

Private Sub picCanvas_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    m_GrabbedPoint = -1
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated