Results 1 to 8 of 8

Thread: Moving Pictures

  1. #1

    Thread Starter
    New Member Ryu's Avatar
    Join Date
    May 2002
    Location
    Japan... I wish. Canada...
    Posts
    7

    Moving Pictures

    Im working on a Resident-Evilish type game on Visual Basics. Im working on a puzzle right now, and I need some help with a simple thing I cant seem to figure out.

    I need to know how to move a picture or Image across the screen by clicking and dragging the mouse.

    I dont know if this is possible, but if it is any one can help me out, I thank you greatly!

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Sure it is. What you do is on the MouseDown event jot down the X and Y coords. Make a boolean that says dragging (cant be local, must be global) and set it to true. Then, on the MouseOver event, see if dragging is true, and if it is, move the picturebox right NewX - ClickX units, and NewY - ClickY units. On the MouseUp event, set dragging to false.

    Unfortunately this has erratic behaviour and doesn't work well. As I recall there is an API version. You may want to look for that.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    New Member Ryu's Avatar
    Join Date
    May 2002
    Location
    Japan... I wish. Canada...
    Posts
    7
    lol thanks for the help but im not so fluent in this "VB talk". Im rather new to this world of coding and I can do the simple's and make something real great, but I dont understand the "talk"

    So if its not too much trouble, could anyone Translate what he was saying into english?

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Well... to drag a picture you need 3 values, the position when you click the picture, the current cursor position when moving it and the picture's position. The cursor position is given to you in the MouseMove event. If the user doesn't hold any button you store the cursor position for later use. When a button is pressed and the cursor moves you get the difference of the current and the last cursor position and add them to the picture box' position.

    Sample: Open a new project, add a picture box and insert this code:

    VB Code:
    1. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     'Static means that the variables aren't set
    3.     'back to 0 when the function is called again
    4.     Static X2 As Long
    5.     Static Y2 As Long
    6.    
    7.     If Button = 1 Then
    8.         'Holding left button
    9.        
    10.         'Add difference from current to last cursor
    11.         'position to the picture box' coordinates
    12.         Picture1.Move Picture1.Left - (X2 - X), Picture1.Top - (Y2 - Y)
    13.        
    14.     Else
    15.         'Store mouse position if no button pressed
    16.         X2 = X
    17.         Y2 = Y
    18.     End If
    19. End Sub

  5. #5

    Thread Starter
    New Member Ryu's Avatar
    Join Date
    May 2002
    Location
    Japan... I wish. Canada...
    Posts
    7
    Thanks alot, you just saved me from hours of suffering.

    Everyone I asked didnt know the answer at all, but alas, you did!

    Thanks again ^_^

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I'm quite sure they all know, however

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I would've posted code but I'm feeling sick today - sorry
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    yaya

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