Results 1 to 3 of 3

Thread: [2005] Moving labels

  1. #1

    Thread Starter
    Junior Member maco's Avatar
    Join Date
    Aug 2006
    Location
    Linköping, Sweden
    Posts
    20

    [2005] Moving labels

    I have project which includes moving some labels around controlled by the user. They are put above an picturebox which simulates a soccer field, where you can put up a tactic. The use is in control of a total of 11 labels above this box. I got the first one working as it should (goalie). But now that I make the defenders (4 of them, that should be able to move anywhere on the field by it self without moving any other of the three defenders) it moves them all!

    They have nothing to do with each other and I can't click any of them accept the first one to the left and move all 4 labels. If I try to move any of the other nothing happens. Try to move the first one and everyone moves.

    Any ideas? Here is the code for the labels and moving them. I only pasted the first 2 defender labels because it's the same for the other 2. If I put them in they will also follow the first one.

    vb Code:
    1. Private Sub player2Label_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseDown
    2.         'check if it's the left button pressed
    3.         If e.Button = Windows.Forms.MouseButtons.Left Then
    4.  
    5.             'store the mouse co-ords
    6.             x = e.X
    7.             y = e.Y
    8.         End If
    9.     End Sub
    10.  
    11.     Private Sub player2Label_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseMove
    12.         'only update if left button is still pressed
    13.         If e.Button = Windows.Forms.MouseButtons.Left Then
    14.  
    15.             'work out the labels new x position
    16.             If e.X > x Then
    17.                 player2Label.Left += e.X - x
    18.             Else
    19.                 player2Label.Left -= x - e.X
    20.             End If
    21.  
    22.             'work out the label new y position
    23.             If e.Y > y Then
    24.                 player2Label.Top += e.Y - y
    25.             Else
    26.                 player2Label.Top -= y - e.Y
    27.  
    28.             End If
    29.         End If
    30.     End Sub
    31.  
    32.     Private Sub player3Label_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseDown
    33.         'check if it's the left button pressed
    34.         If e.Button = Windows.Forms.MouseButtons.Left Then
    35.  
    36.             'store the mouse co-ords
    37.             x = e.X
    38.             y = e.Y
    39.         End If
    40.     End Sub
    41.  
    42.     Private Sub player3Label_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseMove
    43.         'only update if left button is still pressed
    44.         If e.Button = Windows.Forms.MouseButtons.Left Then
    45.  
    46.             'work out the labels new x position
    47.             If e.X > x Then
    48.                 player3Label.Left += e.X - x
    49.             Else
    50.                 player3Label.Left -= x - e.X
    51.             End If
    52.  
    53.             'work out the label new y position
    54.             If e.Y > y Then
    55.                 player3Label.Top += e.Y - y
    56.             Else
    57.                 player3Label.Top -= y - e.Y
    58.  
    59.             End If
    60.         End If
    61.     End Sub

    Another last question, is there another way to move them so they won't end up outside the panel that the picturebox and the labels are inside?
    Last edited by maco; Mar 5th, 2008 at 07:49 AM.

  2. #2
    Member
    Join Date
    Aug 2007
    Posts
    43

    Re: [2005] Moving labels

    Hi

    Your problem is your handlers!

    You've used "Handles player2Label.MouseMove" to execute subs player2Label_MouseMove and player3Label_MouseMove

    Regards

    Xo

  3. #3

    Thread Starter
    Junior Member maco's Avatar
    Join Date
    Aug 2006
    Location
    Linköping, Sweden
    Posts
    20

    Re: [2005] Moving labels

    Hey!

    Didn't see that, and I didn't think about it. I just copied the code and changed everything but the handlers. :/

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