窗口的位置随着某些事件的发生而变化 [英] Position of a window is changing as some event occurs

查看:67
本文介绍了窗口的位置随着某些事件的发生而变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在vb.net开发了一款蛇游戏。一切都很好但是当越来越多的蛇在一个领域接触鼠标时,游戏的整个窗口位置都在变化。请帮我说明为什么会发生这种情况。



我遇到代码后会遇到更改窗口问题的位置。



 如果 snake( 0 ) .Bounds.IntersectsWith(mouse.Bounds)然后 

LengthenSnake()
mouse.Top = r。下一步(Pb_Area.Top,Pb_Area.Bottom - 25
mouse.Left = r。下一步(Pb_Area.Left,Pb_Area.Right - 25

scoreSnake + = 1
得分.Text = scoreSnake * 100
.Controls.Add(鼠标)
mouse.BringToFront()
结束 如果







执行此代码时,如果条件为真,则长度为一条蛇的身份在加长的伤害中增加()。但是我的申请职位发生了变化。为什么会这样?请帮帮我。





这是lengthenSnake()



 私有  Sub  LengthenSnake()
length_of_snake + = 1
snake(length_of_snake)= PictureBox
使用 snake(length_of_snake)
.Width = 10
.Height = 10
.BackColor = Color.White
.Top = snake(length_of_snake - 1 )。Top
Left = snake(length_of_snake - 1 )。左+ 10
结束 使用

.Controls.Add( snake(length_of_snake))
snake(length_of_snake).BringToFront()
结束 Sub

解决方案

在您显示的代码中不会发生这种情况。它可能发生在 LengthenSnake()的调用中,但您没有显示此方法的代码。问题很简单:唯一可以移动窗户的人就是你。搜索你的代码;使用调试器将代码中的位置精确定位。



-SA


< blockquote>再次设置表单位置


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.

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()

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

解决方案

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


Set the form location again where its changing


这篇关于窗口的位置随着某些事件的发生而变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆