Results 1 to 10 of 10

Thread: Positioning Tool

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Post Positioning Tool

    I'd like to create a positioning tool...which can position object by dragging them around in a box...

    I've added a screenshot...as you see it list the X and Y position value of the box...

    Can somebody tell me what's the best way to create this thing? And probably give me a piece of examle code..thanks
    Attached Images Attached Images  

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    something like this

    in mousedown
    firstx = x
    firsty = y

    in mousemove
    object.left = object.left + (x - firstx)
    object.top = object.top + (y - firsty)
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96
    uhm...probably not what I mean...
    I mean what's the best way to drag the objects over a certain area...

  4. #4
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    yes...
    start new project and add a commandbox to it...

    then add this code:

    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.     Command1.Left = Command1.Left + (X - FirstX)
    13.     Command1.Top = Command1.Top + (Y - FirstY)
    14. End If
    15. End Sub
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    if you want to lock it inside the form, do this instead:

    VB Code:
    1. If Command1.Left < 0 Then Command1.Left = 0
    2.     If Command1.Left > Me.ScaleWidth - Command1.Width Then Command1.Left = Me.ScaleWidth - Command1.Width
    3.     If Command1.Top < 0 Then Command1.Top = 0
    4.     If Command1.Top > Me.ScaleHeight - Command1.Height Then Command1.Top = Me.ScaleHeight - Command1.Height
    5.    
    6.     If Command1.Left > 0 And Command1.Left < Me.ScaleWidth - Command1.Width Then Command1.Left = Command1.Left + (X - FirstX)
    7.    
    8.     If Command1.Top > 0 And Command1.Top < Me.ScaleHeight - Command1.Height Then Command1.Top = Command1.Top + (Y - FirstY)
    9.    
    10.     If Command1.Left <= 0 And X - FirstX >= 0 Then Command1.Left = Command1.Left + (X - FirstX)
    11.     If Command1.Left = Me.ScaleWidth - Command1.Width And X - FirstX <= 0 Then Command1.Left = Command1.Left + (X - FirstX)
    12.    
    13.     If Command1.Top = 0 And Y - FirstY >= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
    14.     If Command1.Top = Me.ScaleHeight - Command1.Height And Y - FirstY <= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    UHm...

    UHm..you've probably not seen my screenshot?

  7. #7
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    yes i've seen it!
    my code makes it possible to click an object and move it around...

    wasn't that what you wanted?
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Sorry..!

    Yeah sorry...but I misread it.. I thought it said Commandbox...

    Is there a way of resizing aswell?? So I can just drag it a little bigger...

  9. #9
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    VB Code:
    1. 'change this part
    2. Command1.Left = Command1.Left + (X - FirstX)
    3. Command1.Top = Command1.Top + (Y - FirstY)
    4.  
    5. 'to
    6.  
    7. Command1.width = Command1.width + (X - FirstX)
    8. Command1.height = Command1.height + (Y - FirstY)
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  10. #10
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    try this piece of code:

    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 X <> FirstX Then Command1.Width = Command1.Width + (X - FirstX)
    13.     If Y <> FirstY Then Command1.Height = Command1.Height + (Y - FirstY)
    14.    
    15.     Me.Refresh
    16.    
    17.     FirstX = X
    18.     FirstY = Y
    19. End If
    20.  
    21. If Button = 2 Then
    22.     If Command1.Left < 0 Then Command1.Left = 0
    23.     If Command1.Left > Me.ScaleWidth - Command1.Width Then Command1.Left = Me.ScaleWidth - Command1.Width
    24.     If Command1.Top < 0 Then Command1.Top = 0
    25.     If Command1.Top > Me.ScaleHeight - Command1.Height Then Command1.Top = Me.ScaleHeight - Command1.Height
    26.    
    27.     If Command1.Left > 0 And Command1.Left < Me.ScaleWidth - Command1.Width Then Command1.Left = Command1.Left + (X - FirstX)
    28.    
    29.     If Command1.Top > 0 And Command1.Top < Me.ScaleHeight - Command1.Height Then Command1.Top = Command1.Top + (Y - FirstY)
    30.    
    31.     If Command1.Left <= 0 And X - FirstX >= 0 Then Command1.Left = Command1.Left + (X - FirstX)
    32.     If Command1.Left = Me.ScaleWidth - Command1.Width And X - FirstX <= 0 Then Command1.Left = Command1.Left + (X - FirstX)
    33.    
    34.     If Command1.Top = 0 And Y - FirstY >= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
    35.     If Command1.Top = Me.ScaleHeight - Command1.Height And Y - FirstY <= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
    36. End If
    37.  
    38. End Sub

    left mouse button scales, right moves.
    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