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 9137511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:06:44+00:00 2026-06-17T09:06:44+00:00

I have a WinForm application ‘Bouncing Balls’ , and I need to paint the

  • 0

I have a WinForm application ‘Bouncing Balls’ , and I need to paint the balls
on a bitmap and present the bitmap on this form.

I have a plusButton that adds new ball, and i’m saving each new ball in a list.

Now, the Form_Paint method is telling to each ball to draw himself, it works fine
until there are a lot of balls and the all application become very slow..

Here is my Code:

The paint method of the form code:

 private void Form1_Paint(object sender, PaintEventArgs e)
 {
     ballsArray.drawImage(bmp,e, ClientRectangle);
 }

NOTE: ballsArray is from type AllBalls, this is a class that wraps the ball methods, inside his c’tor i’m creating a list that keeps each ball. the bmp, is created when the form is loading – on Form_Load() method.

The drawImage of ballsArray code:

 public void drawImage(Bitmap bmp,PaintEventArgs e, Rectangle r)
 {
     foreach (Ball b in allBalls)
     {
         b.drawImage(bmp,e, r);
     }
 }

The drawImage of Ball code:

  public void drawImage(Bitmap bmp, PaintEventArgs e, Rectangle r)
  {
      using (Graphics g = Graphics.FromImage(bmp))
      {
          e.Graphics.FillEllipse(brush, ballLocation);
          g.DrawImage(bmp, 0, 0);
      }
  }

NOTE: ballLocation is a rectangle that represent the location of the ball in each
step of movement..

So what I’m doing wrong? What causing the application to be slowly?

I have a constraint to draw everything on the bitmap and present it on the form.
I’m also passing the bitmap that I create when the form is loading, because I need to draw each on it.

  • 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-06-17T09:06:44+00:00Added an answer on June 17, 2026 at 9:06 am

    Some basic techniques to make this fast:

    • Don’t double-buffer yourself and especially don’t double-buffer twice. The double-buffering you get by setting the form’s DoubleBuffer property to true is superior to most any double-buffering you’d do yourself. The buffer is highly optimized to work efficiently with your video adapter’s settings. So completely drop your bmp variable and draw to the e.Graphics you got from the Paint event handler argument.

    • You are not using the passed r argument. Possibly intended to support clipping invisible balls. The one you want to pass is e.ClipRectangle, you can skip painting balls that are completely outside of this rectangle. While that’s an optimization, it isn’t one that’s commonly useful when you use the Aero theme and you do get inconsistent redraw rates so you might want to skip that one.

    • It isn’t very clear why you use both Graphics.FillEllipse and Graphics.DrawImage when you draw the ball. The image ought to overlap the circle so just remove FillEllipse.

    • Pay a lot of attention to the Bitmap object that stores the ball graphic. First thing you want to make sure is that it is drawn with the exact size of the image so it doesn’t have to be rescaled. Rescaling is very expensive. While you don’t have any rescaling in your DrawImage() call, you will still get it if the resolution of the bitmap is not the same as the resolution of your video adapter. The next step will solve that

    • The pixel format of the ball bitmap is very important. You want one that permits copying the bitmap straight to video memory without any format conversion. On any modern machine, that format is PixelFormat.Format32bppPArgb. The difference is enormous, it draws ten times faster than any of the other ones. You won’t get this format from an image resource you added, you’ll have to create that bitmap when your program starts up. Check this answer for the required code.

    You ought to be able to render at least 15 times faster when you follow these guidelines. If that’s still enough then you do need to turn to DirectX, it has the unbeatable advantage of being able to store the ball graphic in video memory so you don’t get the expensive blt from main memory to video memory.

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

Sidebar

Related Questions

I have a winform application that goes with name myForm . Within this form
I have an application (winform exe) that I run several times. Does this mean
I have a c# WinForm application that I need to generate TabPages at runtime.
I have a winform application (one form), on this form there is a RichTextBox.
I have a winform application that contains a c# webbrowser control.Webbrower control load a
I have an c# winform application that runs under a local account but needs
We have an in house winform application that is used by about 20 users
I have winform application written in c#. I would like this application to only
I have a C# winform application that is outputting to excel files. Let's say
I have a C# WinForm application that has a few images on it. I

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.