我正在使用 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 类中的变量和子例程来控制我的标签“球”的运动。任何帮助,建议?