为什么在调试项目时,我的窗体不会显示在 Visual Studio 2010 中?



我使用的是Visual Studio 2010 Professional。

我有一个表单(及其关联的vb文件)和另一个单独的vb文件。当我去编译和调试代码时,我的构建成功了,表单也显示了出来,但"球"并没有移动。

我的启动类:

Public Class Bouncer
Private bouncingBall As Ball
Private Sub CST8333_Lab3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
bouncingBall = New Ball(Me)
'Me.Controls.Add(Ball)
End Sub
Private Sub Timer_Tick(sender As System.Object, e As System.EventArgs) Handles Timer.Tick
bouncingBall.MoveBall()
End Sub
End Class

我的另一个单独的班级:

Public Class Ball
Private ballX As Integer
Private ballY As Integer
Private ballMovementX As Integer
Private ballMovementY As Integer
Private _bouncer As Bouncer
Sub New(bouncer As Bouncer)
_bouncer = bouncer
ballX = 50
ballY = 50
ballMovementX = 5
ballMovementY = 5
End Sub
Public Function GetBallX() As Integer
Return ballX
End Function
Public Sub MoveBall()
If (ballX >= _bouncer.Width) Then
ballMovementX = -ballMovementX
ElseIf (ballX <= 0) Then
ballMovementX = -ballMovementX
End If
If (ballY >= _bouncer.Height) Then
ballMovementY = -ballMovementY
ElseIf (ballY <= 0) Then
ballMovementY = -ballMovementY
End If
ballX += ballMovementX
ballY += ballMovementY
End Sub
End Class

我的状态显示出来,但我的"球"不动。我想要的是Ball类中的变量和子程序来控制标签"Ball"的移动。有什么帮助和建议吗?

您可能应该使用计时器而不是While True循环。While True循环没有给GUI更新屏幕的机会。

假设Ball是一个控件,则需要将其添加到表单的集合:

bouncingBall = New Ball(Me)
Me.Controls.Add(bouncingBall)
bouncingBall.MoveBall()

目前尚不清楚您的Ball课程在做什么。看起来它只是在更新内部变量,而不是实际移动控件,这正是我怀疑你试图实现的。

最新更新