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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:27:45+00:00 2026-05-22T16:27:45+00:00

I am new to c#(using visual c# 2010), and was tying to make a

  • 0

I am new to c#(using visual c# 2010), and was tying to make a simple game, it will have bouncing ball type thing,

I used graphics fillellipse to make a ball, now i have this code with me,

protected override void OnPaint( PaintEventArgs e)
{
    //System.Drawing.Graphics gobj;
    gobj = this.CreateGraphics();
    Pen pen = new Pen(System.Drawing.Color.LightSkyBlue, 6);
    SolidBrush brush = new SolidBrush(System.Drawing.Color.Magenta);
    Rectangle myRectangle = new Rectangle((PointToClient(Cursor.Position).X), PointToClient(Cursor.Position).Y, 250, 200);

    gobj.DrawRectangle(pen, myRectangle);
    gobj.FillEllipse(brush, myRectangle);
} 

when i run this code, i keep on getting many circles and rectangles, popping under a section of screen only, but shouldn’t it draw just a single circle??

Please help me understand this??

  • 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-22T16:27:45+00:00Added an answer on May 22, 2026 at 4:27 pm

    You drawing rectangle with DrawRectangle method and then circle with FillEllipse, you need to use just FillEllipse. And like Mikant mentioned you don’t need to create graphics – use e.Graphics. Here is code:

    protected override void OnPaint(PaintEventArgs e)
    {
        SolidBrush brush = new SolidBrush(System.Drawing.Color.Magenta);
        e.Graphics.FillEllipse(brush, (this.Height / 2) - 40, (this.Width / 2) - 40, 80, 80);
    }
    

    This draws circle in form centre.

    Good luck in experimenting and learning!

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

Sidebar

Related Questions

I am new to using Microsoft development tools but have been using Visual Studio
All: We are using Visual Studio 2010, and we have recently upgraded our workstations
Good Day All, I’m new to programming. I’m using Visual Studio 2010. I’m taking
Good Day All, I’m new to programming. I’m using Visual Studio 2010. I’m taking
I am developing an MVC3 application using Visual Studio 2010. I have an aspx
Using Visual Studio 2010 C++ with googletest. I'm new to unit testing and I've
I have an app in c# using Visual Studio 2010 express and realized the
I'm new to Sharepoint. I'm trying to create a simple webpart using Visual Studio
I already have Visual Studio 2010 SP1 installed. I am using express edition. Also,
Hi all I've just started a new project using Visual Web Developer 2008 Express

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.