Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Feature] Moveable PictureBoxes and Images
#1
Difficulty: 1/5
Sides: Client Only
Tested on: MS4
Works for: MS4
Credits: Me Big Grin
Tutorial Type: Copy and Paste with a Teeny bit of Modification

Description of Variables (You can copy these comments into your program for other programmers to read):
Code:
' OHOX/OHOY are the variables that define the Object Hold Offset X/Y
' MouseDown is the boolean that determines whether the Mouse is still pressed or not
' CFrm is the Current Form that the player is viewing
' CPic is the Current PictureBox that the player is trying to Move
' CImg is the Current Image that the player is trying to Move
' DX/DY are the variables that define the Destination X/Y


Put the following in modDatabase under Option Explicit:
Code:
Public DX, DY as Long
Public OHOX, OHOY As Long
Public MouseDown As Boolean

Put The Following Code In the Form's Code Editor (Whichever form contains the picture you want to move) And Replace the 's with the name of the Picture you want to move:
Code:
Private Sub _MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    OHOX = X
    OHOY = Y
    MouseDown = True
End Sub

Private Sub _MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If MouseDown = True Then Call PicMove(Me, Me., Button, Shift, CLng(X), CLng(Y))
End Sub

Private Sub _MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    MouseDown = False
End Sub

Put The Following Code In the Form's Code Editor (Whichever form contains the image you want to move) And Replace the 's with the name of the Img you want to move:
Code:
Private Sub _MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    OHOX = X
    OHOY = Y
    MouseDown = True
End Sub

Private Sub _MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If MouseDown = True Then Call ImgMove(Me, Me., Button, Shift, CLng(X), CLng(Y))
End Sub

Private Sub _MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    MouseDown = False
End Sub

And Put this in modDatabase at the bottom:
Code:
Public Sub PicMove(CFrm As Form, CPic As PictureBox, Button As Integer, Shift As Integer, X As Long, Y As Long)
    
    If Button = 1 Then
        DX = CPic.Left + X - OHOX
        DY = CPic.Top + Y - OHOY
        If DX < 0 Then DX = 0
        If DY < 0 Then DY = 0
        If DX + CPic.Width > CFrm.ScaleWidth Then DX = CFrm.ScaleWidth - CPic.Width
        If DY + CPic.Height > CFrm.ScaleHeight Then DY = CFrm.ScaleHeight - CPic.Height
        CPic.Left = DX
        CPic.Top = DY
    End If
End Sub

Public Sub ImgMove(CFrm As Form, CImg As Image, Button As Integer, Shift As Integer, X As Long, Y As Long)
    
    If Button = 1 Then
        DX = CImg.Left + X - OHOX
        DY = CImg.Top + Y - OHOY
        If DX < 0 Then DX = 0
        If DY < 0 Then DY = 0
        If DX + CImg.Width > CFrm.ScaleWidth Then DX = CFrm.ScaleWidth - CImg.Width
        If DY + CImg.Height > CFrm.ScaleHeight Then DY = CFrm.ScaleHeight - CImg.Height
        CFrm.ScaleMode = 1
        CImg.Left = DX
        CImg.Top = DY
    End If
End Sub
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)