Results 1 to 7 of 7

Thread: Moving/Draggin Image Box???

  1. #1

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188

    Question Moving/Draggin Image Box???

    hey all,

    How do you drag/move and image box on a form??

    thanks
    b

  2. #2
    Hyperactive Member beasty1711's Avatar
    Join Date
    Mar 2001
    Posts
    418
    is it the actual box that you want to move, or is it the image inside the box?
    "...They even have the internet on computers..." :- Homer Simpson

    "Second Place is First Looser" :- No Fear

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    To move the box :

    VB Code:
    1. Private prevX As Single, prevY As Single
    2.  
    3. Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.     If Button = 1 Then Image1.Move Image1.Left - (prevX - X), Image1.Top - (prevY - Y)
    5. End Sub
    6.  
    7. Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    8.     prevX = X
    9.     prevY = Y
    10. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    hi
    Another way is to use drag drop so as to only display the outline and hence stop any flickering of the image control
    Regards
    Stuart
    VB Code:
    1. Dim fsngDragOrigTop As Single
    2. Dim fsngDragOrigLeft As Single
    3. Dim fsngDragOrigX As Single
    4. Dim fsngDragOrigY As Single
    5.  
    6. Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    7.     With Image1
    8.         fsngDragOrigTop = .Top
    9.         fsngDragOrigLeft = .Left
    10.         fsngDragOrigX = X
    11.         fsngDragOrigY = Y
    12.         .Drag vbBeginDrag
    13.     End With
    14. End Sub
    15.  
    16. Private Sub image1_DragDrop(Source As Control, X As Single, Y As Single)
    17.     'In case user doesnt move out of area of image control
    18.     With Image1
    19.         .Left = fsngDragOrigLeft + (X - fsngDragOrigX)
    20.         .Top = fsngDragOrigTop + (Y - fsngDragOrigY)
    21.         .Drag vbEndDrag
    22.     End With
    23. End Sub
    24.  
    25. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    26.     On Error Resume Next
    27.     With Source
    28.         .Left = (X - fsngDragOrigX)
    29.         .Top = (Y - fsngDragOrigY)
    30.         .Drag vbEndDrag
    31.     End With
    32. End Sub

    PS. And Jamie, don't swear at me this time like the last few posts!!!
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  5. #5

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    The actual box!

    Cool ta jamie!

  6. #6

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    nah swear at him!!

    hehe
    thanks Stuart!
    I'll give em both a go!

    all here!

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    bollox beachbum

    n/p beacon.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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