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

  • Home
  • SEARCH
  • 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 851691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:28:13+00:00 2026-05-15T07:28:13+00:00

I’m trying to implement the following method: void Ball::DrawOn(Graphics g); The method should draw

  • 0

I’m trying to implement the following method:
void Ball::DrawOn(Graphics g);

The method should draw all previous locations (stored in a queue) of the ball and finally the current location. I don’t know if that matters, but I print the previous locations using g.DrawEllipse(...) and the current location using g.FillEllipse(...).

The question is, that as you could imagine there is a lot of drawing to be done and thus the display starts to flicker much. I had searched for a way to double buffer, but all I could find is these 2 ways:

  1. System.Windows.Forms.Control.DoubleBuffered = true;

  2. SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);

while trying to use the first, I get the an error explaining that from in this method the Property DoubleBuffered is inaccessible due to its protection level. While I can’t figure how to use the SetStyle method.

Is it possible at all to double buffer while all the access I have is to the Graphics Object I get as input in the method?

Thanks in Advance,

Edit:
I had created the following class

namespace doubleBuffer
{
    class BufferedBall : System.Windows.Forms.Form
    {
        private Ball ball;
        public BufferedBall(Ball ball)
        {
            this.ball = ball;
        }

        public void DrawOn(Graphics g)
        {
            this.DoubleBuffered = true;
            int num = 0;
            Rectangle drawArea1 = new Rectangle(5, 35, 30, 100);
            LinearGradientBrush linearBrush1 =
            new LinearGradientBrush(drawArea1, Color.Green, Color.Orange, LinearGradientMode.Horizontal);
            Rectangle drawArea2 = new Rectangle(5, 35, 30, 100);
            LinearGradientBrush linearBrush2 =
               new LinearGradientBrush(drawArea2, Color.Black, Color.Red, LinearGradientMode.Vertical);
            foreach (Point point in ball.previousLocations)
            {
                Pen myPen1;
                if (num % 3 == 0)
                    myPen1 = new Pen(Color.Yellow, 1F);
                else if (num % 3 == 1)
                    myPen1 = new Pen(Color.Green, 2F);
                else
                    myPen1 = new Pen(Color.Red, 3F);
                num++;
                myPen1.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                myPen1.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
                myPen1.EndCap = System.Drawing.Drawing2D.LineCap.AnchorMask;
                g.DrawEllipse(myPen1, (float)(point.X - ball.radius), (float)(point.Y + ball.radius), (float)(2 * ball.radius), (float)(2 * ball.radius));
            }
            if ((ball.Host.ElapsedTime * ball.Host.FPS * 10) % 2 == 0)
            {
                g.FillEllipse(linearBrush1, (float)(ball.Location.X - ball.radius), (float)(ball.Location.Y + ball.radius), (float)(2 * ball.radius), (float)(2 * ball.radius));
            }
            else
            {
                g.FillEllipse(linearBrush2, (float)(ball.Location.X - ball.radius), (float)(ball.Location.Y + ball.radius), (float)(2 * ball.radius), (float)(2 * ball.radius));
            }
        }
    }
}

and the ball drawOn looks like this:

new BufferedBall(this).DrawOn(g);

Is that what you meant? because it is still flickering?

  • 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-15T07:28:13+00:00Added an answer on May 15, 2026 at 7:28 am

    Form class has DoubleBuffered property exposed as protected. http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx but since you derive your form from Form you can use it.

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

Sidebar

Ask A Question

Stats

  • Questions 477k
  • Answers 477k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you use the MOXy JAXB implementation you can do… May 16, 2026 at 5:17 am
  • Editorial Team
    Editorial Team added an answer Java doesn't actually have unsigned primitives. The value 127 is… May 16, 2026 at 5:17 am
  • Editorial Team
    Editorial Team added an answer You need a custom source-option implementation for reading the xml… May 16, 2026 at 5:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.