Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
XML RSS Feed
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleLet the user modify a polygon with grab handles
Keywordspolygon, drag, grab handles
CategoriesGraphics
 
Keep the list of polygon vertices in arrays. In the MouseDown event handler, search the vertices to see if the point is close to a vertex. If it is, start dragging.
 
' See if we are over a grab handle.
Private Sub Form_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
Dim i As Integer
Dim dx As Single
Dim dy As Single

    For i = 1 To m_NumPoints
        If Abs(m_PointX(i) - X) < HANDLE_HALF_WIDTH And _
           Abs(m_PointY(i) - Y) < HANDLE_HALF_WIDTH _
        Then
            ' We are over this grab handle.
            ' Start dragging.
            m_DraggingHandle = i
            Exit For
        End If
    Next i
End Sub

' Move the drag handle.
Private Sub Form_MouseMove(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    ' Do nothing if we are not dragging.
    If m_DraggingHandle = 0 Then Exit Sub

    ' Move the handle.
    m_PointX(m_DraggingHandle) = X
    m_PointY(m_DraggingHandle) = Y

    ' Redraw.
    Refresh
End Sub

' Stop dragging.
Private Sub Form_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    m_DraggingHandle = 0
End Sub
 
For more information on graphics programming in Visual Basic, see my book Visual Basic Graphics Programming.
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated