Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:40:23+00:00 2026-05-30T06:40:23+00:00

I am trying to create a simply bouncy ball application in VB net; I

  • 0

I am trying to create a simply bouncy ball application in VB net;
I am using a timer and the FillEllipse() method to try ad create a new circle at every tick of the timer.
Code:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim Gr As Graphics = Me.CreateGraphics

        Gr.FillEllipse(Brushes.Teal, X, Y, W, H)
        CollisionDetect()
        X = X + X_Dir
        Y = Y + Y_Dir

        Gr.Dispose()

    End Sub

The result? The form continously draws onto itself, without clearing the last circle. This means that you end up with a ‘line’ of spheres together.

To clarify:
X is well, the X-Coords
Y is Y- Y-Coords

X_Dir is an integer, it is added to every iteration of the loop so the next time the loop iterates, it’ll be at a different location;
Y_Dir is the same but for the Y Coords;

CollisionDetect() Is empty. It is yet to be filled, it will handle the collision with the sides of the forms.
W, H are width and height, respectively.

Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:40:24+00:00Added an answer on May 30, 2026 at 6:40 am

    Usually painting is done when the Paint event is fired. Add a Panel control with the desired background color to your form. Handle the Paint event of your panel

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        e.Graphics.FillEllipse(Brushes.Teal, X, Y, W, H)   
    End Sub
    

    The panel will always automatically be cleared before you draw.

    Change the timer tick event handler to

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Panel1.Invalidate() ' This triggers the Paint event
        CollisionDetect()   
        X = X + X_Dir   
        Y = Y + Y_Dir   
    End Sub
    

    Note that the Paint event is fired automatically, if the panel was hidden by another form, for instance, and has to be redrawn. If the computer is busy and cannot paint, some paint events may be skipped. Therefore keep your game logic (calculation) in Timer1_Tick.


    If you prefer to draw directly on the form, you can do that by using the form’s paint event instead of the panel’s paint event and by calling Me.Invalidate() instead of Panel1.Invalidate().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create simply connect with ActiveMQ using JNDI. I have: Queue named
I am new to using matplotlib. I am trying to create a 2D grid,
So I have been struggling for days now, trying to simply create a new
I'm trying to create a loggers hierarchy in my application. (I'm using standard java
i am trying to create a method to access an access2010 .accdb database simply
I'm simply trying to create a UML diagram where I can show the header
I'm trying to create an app for Android that simply sends a command to
I am trying to create a very simple chat window that simply has the
I'm trying to create a simple Add-On for SQL Server 2008; it is simply
what i'm trying to do this this. Simply create a C# windows app that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.