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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:32:54+00:00 2026-05-27T01:32:54+00:00

I drew some circles on the Form1 using GDI+ , and the center of

  • 0

I drew some circles on the Form1 using GDI+, and the center of the circle is a small red rectangle of Custom Control which is derived from User Control, the BackgroundImage property ofForm1‘s a bitmap which is also drawn by GDI+ with several colors.

What I want is that when I move the red rectangle(the center of circle) with a mouse, the circle will also move following the red rectangle. Using the MouseDown, MouseMove event I could move the red rectangle smoothly with the mouse.

My problem is how to move the circle corresponding to the red rectangle(the center of circle).
I enabled the double buffering to solve the flicker problem. CircleCenter is an object of Custom Control class(e.g. the red rectangle). GObject is a Grahpics object.
Here is some key codes:

   public Form1()
   {
        InitializeComponent();
        this.SetStyle(ControlStyles.DoubleBuffer |    //enables double-buffering
                      ControlStyles.UserPaint |
                      ControlStyles.AllPaintingInWmPaint,
                      true);
    }

   Point CCenterPoint = new Point();
   private int Diameter = 250;
   private void CircleCenterMouseDown(object sender, MouseEventArgs e)
   {
        CCenterPoint = new Point(-e.X, -e.Y);
   }

    private void CircleCenterMouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
                Point MousePos = CircleCenter.MousePosition;
                MousePos.Offset(CCenterPoint.X, CCenterPoint.Y);
                CircleCenter.Location = CircleCenter.Parent.PointToClient(MousePos);
                CircleCenter.BringToFront();
                CirclePen.Color = Color.Black;
                GObject.DrawEllipse(CirclePen, CircleCenter.Left- Diameter/2, CircleCenter.Top - Diameter/2, Diameter, Diameter);
                 this.Invalidate();
        }
    }

How to remove the black circle drawn by GDI+ produced in the MouseMove proceed?
I googled several websites and didn’t get a satisfied answer. Hope you could give me some hints,Thx!

  • 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-27T01:32:55+00:00Added an answer on May 27, 2026 at 1:32 am

    Well, As I understand from your question, You just need to draw a circle around the red rectangle, This is quite easy.

    In the Paint event of the Form, Add the following (assuming that your red rectangle control has the name “CircleCenter” and your Form was named “Form1”):

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        // get the Graphics object of the form.
        Graphics g = e.Graphics;
        // create a think red pen for the circle drawing
        Pen redPen = new Pen(Brushes.Red, 4.0f);
        // drawing the circle
        PointF ctrlCenter = GetCenterOfControl(CircleCenter);
        g.DrawEllipse(redPen,
                ctrlCenter.X - (Diameter / 2),
                ctrlCenter.Y - (Diameter / 2),
                Diameter, Diameter);
    }
    
    //The following little method to calculate the center point
    PointF GetCenterOfControl(Control ctrl)
    {
        return new PointF(ctrl.Left + (ctrl.Width / 2),
                ctrl.Top + (ctrl.Height / 2));
    }
    

    Any way, I know it looks long for such a simple task like Circle drawing! here is the ugly one line version of the above code:

    e.Graphics.DrawEllipse(new Pen(Brushes.Red, 4.0f), (centerCircle.Left + (centerCircle.Width / 2)) - (Diameter / 2), (centerCircle.Top + (centerCircle.Height / 2)) - (Diameter / 2), Diameter, Diameter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some custom table view cells that takes a while to draw, so
I have a custom view with some drawing on it. I want to resize
I'm trying to create a constructor for a custom type, but for some reason,
I'm using Gnuplot to draw a graph. In the graph I drew three smooth
I have a WinForms application with some business objects which implement INotifyPropertyChanged and hook
I am new to iphone development, and i'm currently using xcode 4.2. I drew
I drew some quad like this with OpenGL: _______ _______ | || | |
So, I'm doing some custom drawing in a UIControl subclass by overriding the drawRect:
I'm using this code to colorize some images of a UIButton subclass: UIImage *img
Was thinking it should be pretty easy to create a ProgressBar that drew some

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.