Difficulty: 1/5
Sides: Client Only
Tested on: MS4
Works for: MS4
Credits: Me
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 <PicName>'s with the name of the Picture you want to move:
Code:
Private Sub <PicName>_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
OHOX = X
OHOY = Y
MouseDown = True
End Sub
Private Sub <PicName>_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MouseDown = True Then Call PicMove(Me, Me.<PicName>, Button, Shift, CLng(X), CLng(Y))
End Sub
Private Sub <PicName>_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 <ImgName>'s with the name of the Img you want to move:
Code:
Private Sub <ImgName>_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
OHOX = X
OHOY = Y
MouseDown = True
End Sub
Private Sub <ImgName>_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MouseDown = True Then Call ImgMove(Me, Me.<ImgName>, Button, Shift, CLng(X), CLng(Y))
End Sub
Private Sub <ImgName>_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