Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hello,
I have developed a snake game in vb.net. everything is working fine but when the increasing snake touches the mouse in a field then the whole window position of a game is changing. Please help me by telling why this is happening.

I am giving the code after encountering which i get a changing position of window problem.

VB
If snake(0).Bounds.IntersectsWith(mouse.Bounds) Then

           LengthenSnake()
           mouse.Top = r.Next(Pb_Area.Top, Pb_Area.Bottom - 25)
           mouse.Left = r.Next(Pb_Area.Left, Pb_Area.Right - 25)

           scoreSnake += 1
           score.Text = scoreSnake * 100
           Me.Controls.Add(mouse)
           mouse.BringToFront()
       End If



When this code is executed and when if condition is true, the length of a snake id increased in a lengthenSnake(). but while the position of my application changes. Why it is happening? Please help me out.


Here is lengthenSnake()

VB
Private Sub LengthenSnake()
       length_of_snake += 1
       snake(length_of_snake) = New PictureBox
       With snake(length_of_snake)
           .Width = 10
           .Height = 10
           .BackColor = Color.White
           .Top = snake(length_of_snake - 1).Top
           Left = snake(length_of_snake - 1).Left + 10
       End With

       Me.Controls.Add(snake(length_of_snake))
       snake(length_of_snake).BringToFront()
   End Sub
Posted
Updated 5-Aug-14 22:25pm
v2
Comments
Kschuler 5-Aug-14 14:05pm    
You might want to include the code for LengthenSnake(). Click the Improve question link and add it to your question.
BCD23 6-Aug-14 4:30am    
included the sub lengthensnake()

It does not happen in the code you show. It can happen in the call to LengthenSnake(), but you didn't show the code of this method. The problem is simple: the only person who could move the window is you. Search your code; use the debugger to pin-point the place in code where you do it.

—SA
 
Share this answer
 
Set the form location again where its changing
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900