Results 1 to 6 of 6

Thread: Draging an image around

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Switzerland
    Posts
    45

    Draging an image around

    Hey there

    I'm looking for code to drag an image around on a form. I tried it with the mousedown event of the image but had no luck with that. It should be like the position-bar of winamp... where i can drag the Position-handler to the desired destination.

    Any help would be appreciated very much

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Record a X and Y coordinat int the mouse down event...and in the mouse move event update the picturebox left and top property after the diffrence in the X and Y coordinate when you started and what they are now....

  3. #3
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    Yes...Here's an example i made some time ago:


    Start a new project and add a CommandButton

    the paste this code into the form:
    VB Code:
    1. Option Explicit
    2. Dim FirstX As Single
    3. Dim FirstY As Single
    4.  
    5. Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    6. FirstX = X
    7. FirstY = Y
    8. End Sub
    9.  
    10. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    11. If Button = 1 Then
    12.     If Command1.Left < 0 Then Command1.Left = 0
    13.     If Command1.Left > Me.ScaleWidth - Command1.Width Then Command1.Left = Me.ScaleWidth - Command1.Width
    14.     If Command1.Top < 0 Then Command1.Top = 0
    15.     If Command1.Top > Me.ScaleHeight - Command1.Height Then Command1.Top = Me.ScaleHeight - Command1.Height
    16.    
    17.     If Command1.Left > 0 And Command1.Left < Me.ScaleWidth - Command1.Width Then Command1.Left = Command1.Left + (X - FirstX)
    18.    
    19.     If Command1.Top > 0 And Command1.Top < Me.ScaleHeight - Command1.Height Then Command1.Top = Command1.Top + (Y - FirstY)
    20.    
    21.     If Command1.Left <= 0 And X - FirstX >= 0 Then Command1.Left = Command1.Left + (X - FirstX)
    22.     If Command1.Left = Me.ScaleWidth - Command1.Width And X - FirstX <= 0 Then Command1.Left = Command1.Left + (X - FirstX)
    23.    
    24.     If Command1.Top = 0 And Y - FirstY >= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
    25.     If Command1.Top = Me.ScaleHeight - Command1.Height And Y - FirstY <= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
    26.    
    27.     Command1.Caption = "(" & Command1.Left / Screen.TwipsPerPixelX & "," & Command1.Top / Screen.TwipsPerPixelY & ")"
    28.    
    29. End If
    30. End Sub
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Yes..that code should do the trick....

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Switzerland
    Posts
    45
    thx alot for the help figured it out by myself in the meantime...

  6. #6
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    hehe ok
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

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