Results 1 to 16 of 16

Thread: best way to float and move randomly a picture on top of a vb6 form

Threaded View

  1. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: best way to float and move randomly a picture on top of a vb6 form

    Use a Picturebox or an Image Control

    Code:
    Dim nX As Single
    Dim nY As Single
    
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
     nX = X / Screen.TwipsPerPixelX
     nY = Y / Screen.TwipsPerPixelY
    End Sub
    
    Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     If Button = 1 Then
       Image1.Move Image1.Left + ((X / Screen.TwipsPerPixelX)) - nX, Image1.Top + ((Y / Screen.TwipsPerPixelY)) - nY
     End If
    End Sub
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
     nX = X / Screen.TwipsPerPixelX
     nY = Y / Screen.TwipsPerPixelY
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     If Button = 1 Then
       Picture1.Move Picture1.Left + ((X / Screen.TwipsPerPixelX)) - nX, Picture1.Top + ((Y / Screen.TwipsPerPixelY)) - nY
     End If
    End Sub
    NOTE: If your Picturebox has it's ScaleMode = vbPixels then don't use the Screen.TwipsPerPixelX and Screen.TwipsPerPixelY
    Last edited by jmsrickland; Aug 6th, 2012 at 09:46 AM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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