Results 1 to 2 of 2

Thread: Moving Multiple Controls

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2002
    Posts
    70

    Moving Multiple Controls

    I am looking for some help on moving controls by dragging.

    Say I have three controls on a form. I'd like to be able to hold down the left mouse button on ANY one of them, and wherever I drag the controls (they would move with the mouse, not just a drag icon) and drop them, they would keep there relative positions from each other, just at a different place on the form.

    As an example, take a flow charting app like Visio. With more than one shape selected, the user can drag the shapes anywhere in the working area. This is what I'm looking for.

    Any help would be appreciated, even a shove in the right direction.

    Thanks.

    Imp

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    This example is using a picture box, but you can use anything that has the MouseDown and MouseMove events.
    VB Code:
    1. ' Global variables...
    2. Private Pic1X As Single, Pic1Y As Single
    3.  
    4. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    5.     If Button = 1 Then
    6.         Pic1X = X
    7.         Pic1Y = Y
    8.     End If
    9. End Sub
    10.  
    11. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    12.     If Button = 1 Then
    13.         Picture1.Left = Picture1.Left - (Pic1X - X)
    14.         Picture1.Top = Picture1.Top - (Pic1Y - Y)
    15.     End If
    16. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width