|
-
Mar 5th, 2008, 07:42 AM
#1
Thread Starter
Junior Member
[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:
Private Sub player2Label_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseDown 'check if it's the left button pressed If e.Button = Windows.Forms.MouseButtons.Left Then 'store the mouse co-ords x = e.X y = e.Y End If End Sub Private Sub player2Label_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseMove 'only update if left button is still pressed If e.Button = Windows.Forms.MouseButtons.Left Then 'work out the labels new x position If e.X > x Then player2Label.Left += e.X - x Else player2Label.Left -= x - e.X End If 'work out the label new y position If e.Y > y Then player2Label.Top += e.Y - y Else player2Label.Top -= y - e.Y End If End If End Sub Private Sub player3Label_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseDown 'check if it's the left button pressed If e.Button = Windows.Forms.MouseButtons.Left Then 'store the mouse co-ords x = e.X y = e.Y End If End Sub Private Sub player3Label_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles player2Label.MouseMove 'only update if left button is still pressed If e.Button = Windows.Forms.MouseButtons.Left Then 'work out the labels new x position If e.X > x Then player3Label.Left += e.X - x Else player3Label.Left -= x - e.X End If 'work out the label new y position If e.Y > y Then player3Label.Top += e.Y - y Else player3Label.Top -= y - e.Y End If End If 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|