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 controls
DescriptionThis example shows how to let the user move controls in Visual Basic 6.
Keywordscontrol, move control
CategoriesControls, Software Engineering
 
Thanks to Hisham Nassef.

In a control's MouseDown event handler, save the mouse position. In the MouseMove event handler, move the control by the distance the mouse has moved.

 
Private Sub Command1_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    xDown = X
    yDown = Y
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    If Button <> vbRightButton Then Exit Sub

    MoveCtl Command1, X, Y
End Sub

Private Sub MoveCtl(ctl As Object, X As Single, Y As Single)
Dim newLeft As Single
Dim newTop As Single

    newLeft = ctl.Left + X - xDown
    newTop = ctl.Top + Y - yDown
    ctl.Move newLeft, newTop
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated