Results 1 to 2 of 2

Thread: help!! drag & drop images to a grid

  1. #1

    Thread Starter
    Lively Member haruki's Avatar
    Join Date
    Mar 2005
    Location
    Shibuya / Japan
    Posts
    118

    help!! drag & drop images to a grid

    How do I create a grid like the one in edit mode, then be able to drag images that snap. What im trying to create i somewhat like the diablo inventory.

    Anyone??

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: help!! drag & drop images to a grid

    Here's some code that does it (image named Image1). When you release the mouse button the image snaps into place. You can change the grid size by altering the value of the constant.

    VB Code:
    1. Private Const GridSize As Single = 1200
    2.  
    3. Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.     Static mouseposx As Single, mouseposy As Single
    5.     If Button = 1 Then
    6.         Image1.Left = Image1.Left + X - mouseposx
    7.         Image1.Top = Image1.Top + Y - mouseposy
    8.       Else
    9.         mouseposx = X
    10.         mouseposy = Y
    11.     End If
    12. End Sub
    13.  
    14. Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    15.     If Button = 1 Then
    16.         Image1.Left = Round(Image1.Left / GridSize, 0) * GridSize
    17.         Image1.Top = Round(Image1.Top / GridSize, 0) * GridSize
    18.     End If
    19. End Sub

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