cosa intendi per x1 a sinistra, x2 a destra, y1 in alto e y2 in basso?
EDIT: ho tirato fuori questa schifezza:
Spoiler :
VBNET Programming
Private rnd_x, rnd_y As Integer
Dim xp1 = PictureBox1.Location .X + PictureBox1.Width
Dim xp2 = PictureBox2.Location .X + PictureBox2.Width
Dim x1 = PictureBox1.Location .X
Dim x2 = PictureBox2.Location .X
Dim yp1 = PictureBox1.Location .Y + PictureBox1.Height
Dim yp2 = PictureBox2.Location .Y + PictureBox2.Height
Dim y1 = PictureBox1.Location .Y
Dim y2 = PictureBox2.Location .Y
If xp1 >= xp2 Or xp1 <= x2 And yp1 >= yp2 Or yp1 <= y2 Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
End If
(naturalmente sono solo i codici interessati)
e questo è il risultato del debug:
[Per vedere i link devi REGISTRARTI .]
RI-EDIT:
sono ruscito a risolvere il problema sopra indicato, però il codice non funziona a dovere...
RI-RI-EDIT:
ho provato con questo mettendolo in un timer, in modo che è sempre in grado di localizzare la posizione, però quando la pb1 è sulla pb2 cmq nn funziona:
Spoiler :
VBNET Programming
If PictureBox1.Location .X = PictureBox2.Location .X Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
ElseIf PictureBox1.Location .X = PictureBox2.Location .Y Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
ElseIf PictureBox1.Location .Y = PictureBox2.Location .X Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
ElseIf PictureBox1.Location .Y = PictureBox2.Location .Y Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
ElseIf PictureBox2.Location .X = PictureBox1.Location .X Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
ElseIf PictureBox2.Location .X = PictureBox1.Location .Y Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
ElseIf PictureBox2.Location .Y = PictureBox1.Location .X Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
ElseIf PictureBox2.Location .Y = PictureBox1.Location .Y Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
End If
RI-RI-RI-EDIT
:
diciamo che ho risolto... mi accontento con questo:
Spoiler :
VBNET Programming
If PictureBox1.Location .X = PictureBox2.Location .X And PictureBox1.Location .Y = PictureBox2.Location .Y Then
pnt.Text += 1
rnd_x = CInt ( Int ( ( ( Panel1.Width - PictureBox2.Width ) * Rnd ( ) ) + 1 ) )
rnd_y = CInt ( Int ( ( ( Panel1.Height - PictureBox2.Height ) * Rnd ( ) ) + 1 ) )
Dim a As New System.Drawing .Point ( rnd_x, rnd_y)
PictureBox2.Location = a
End If