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 drag a vertical line side to side
Keywordsdrag, line, sash, rubberband
CategoriesGraphics
 
Start drawing with DrawMode = vbInvert in the MouseDown event handler. Continue dragging in MouseMove. Stop in MouseUp. Use form-level variables m_X and m_Drawing to record the mouse's current X coordinate and whether we are dragging the line.
 
Dim m_X As Single
Dim m_Drawing As Boolean

Private Sub Form_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    m_Drawing = True
    DrawMode = vbInvert
    DrawWidth = 4
    m_X = X
    Line (m_X, ScaleTop)-(m_X, ScaleHeight)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    If Not m_Drawing Then Exit Sub
    Line (m_X, ScaleTop)-(m_X, ScaleHeight)
    m_X = X
    Line (m_X, ScaleTop)-(m_X, ScaleHeight)
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    m_Drawing = False
    Line (m_X, ScaleTop)-(m_X, ScaleHeight)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated