Im trying to program pong in vb.net but I cant get the ball on the screen. I use the solidbrush method to draw a ball and the timer event with refresh. I know it has something to do with the paint event but I dont know the exact code. Ive got something like this :
Code:
Private dirUp As Boolean
Private dirLeft As Boolean
Private ballHeight As Integer = 10
Private ballWidth As Integer = 10
Private ballColor As New SolidBrush(Color.DarkKhaki)
Private ballX As Integer
Private ballY As Integer
Private maxHeight As Integer
Private maxWidth As Integer
Sub Tekenbal(ByVal e As System.Windows.Forms.DrawItemEventArgs)
Me.CreateGraphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
Me.CreateGraphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighSpeed
e.Graphics.FillEllipse(ballColor, 10, 10, 10, 10)
End Sub
Sub Beweegbal()
If dirUp = True Then
ballY = ballY - 10
Else
ballY = ballY + 10
End If
If dirLeft = True Then
ballX = ballX - 10
ElseIf Not dirLeft Then
ballX = ballX + 10
End If
If ballHeight + ballY >= maxHeight Then
dirUp = True Weer naar boven
Else
dirUp = False
End If
If ballWidth + ballX >= maxWidth Then
dirLeft = True Naar links
Else
dirLeft = False
End If
If ballY <= 0 Then
dirUp = True Naar beneden
End If
If ballX <= 0 Then
dirLeft = True Naar rechts
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Refresh()
Tekenbal(e) It says System.Windows.Forms.PaintEventArgs cannot be converted to System.Windows.Forms.DrawItemEventArgs
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
maxWidth = Me.Width
maxHeight = Me.Height - 30
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Tekenbal(e) It says System.Windows.Forms.PaintEventArgs cannot be converted to System.Windows.Forms.DrawItemEventArgs
Beweegbal()
End Sub