How to delete a drawn circle in c# windows form?

You have to clear your Graphic:

Graphics.Clear();

But all drawn figures will be cleared. Simply, you will then need to redraw all figures except that circle.

Also, you can use the Invalidate method:

Control.Invalidate()

It indicates a region to be redrawn inside your Graphics. But if you have intersecting figures you will have to redraw the figures you want visible inside the region except the circle.

This can become messy, you may want to check out how to design a control graph or use any graph layout library.


You can invalidate the draw region you want to refresh for example:

 this.Invalidate();

on the form...


Assuming you're subscribing to the Paint event or overriding the protected OnPaint routine, then you will need to perform something like this:

bool paint = false;

protected override void OnPaint(object sender, PaintEventArgs e)
{
  if (paint) 
  {
   // Draw circle.
  }
}

Then when you want to stop painting a circle:

paint = false;
this.Invalidate(); // Forces a redraw

Tags:

C#

Graphics