Question [vb 2008] Bouncing ball

magobin

New member
Joined
Jul 25, 2008
Messages
2
Programming Experience
Beginner
Hi at all,
I'm writing a little joke, where I capture the screen and I use it as background image for a form and a ball bouncing in it
Now I want that bouncing ball path is colored/erased...is possible?
Can someone help me ?
thanks in advance
alex

VB.NET:
Option Strict Off
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Const BALL_WID As Integer = 50
    Private Const BALL_HGT As Integer = 50
    Private m_Dx As Integer
    Private m_Dy As Integer
    Private m_X As Integer
    Private m_Y As Integer
    Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
    ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim pippo As Image
        keybd_event(Windows.Forms.Keys.PrintScreen, 0, 0, 0)
        pippo = Clipboard.GetImage()
        Me.FormBorderStyle = 0
        Me.BackgroundImage = pippo
        Dim rnd As New Random
        m_Dx = rnd.Next(1, 4)
        m_Dy = rnd.Next(1, 4)
        m_X = rnd.Next(0, Me.ClientSize.Width - BALL_WID)
        m_Y = rnd.Next(0, Me.ClientSize.Height - BALL_HGT)
        Me.SetStyle( _
        ControlStyles.AllPaintingInWmPaint Or _
        ControlStyles.UserPaint Or _
        ControlStyles.DoubleBuffer, _
        True)
        Me.UpdateStyles()
    End Sub
    Private Sub tmrMoveBall_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMoveBall.Tick
        m_X += m_Dx
        If m_X < 0 Then
            m_Dx = -m_Dx
        ElseIf m_X + BALL_WID > Me.ClientSize.Width Then
            m_Dx = -m_Dx
        End If
        m_Y += m_Dy
        If m_Y < 0 Then
            m_Dy = -m_Dy
        ElseIf m_Y + BALL_HGT > Me.ClientSize.Height Then
            m_Dy = -m_Dy
        End If
        Me.Invalidate()
    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        e.Graphics.FillEllipse(Brushes.Blue, m_X, m_Y, BALL_WID, BALL_HGT)
        e.Graphics.DrawEllipse(Pens.Black, m_X, m_Y, BALL_WID, BALL_HGT)
        'e.Graphics.Clear(BackColor)
    End Sub
End Class
 
Back
Top