public partial class Circleform : Form
{
public Circleform()
{
InitializeComponent();
}
public class circle
{
public Point startPoint = new Point();
public Point endPoint = new Point();
}
circle l = new circle();
List<circle> allcircle = new List<circle>();
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
foreach (var aLine in allcircle)
{
int dis = (aLine.endPoint.X - aLine.startPoint.X) * (aLine.endPoint.X - aLine.startPoint.X) + (aLine.endPoint.Y - aLine.startPoint.Y) * (aLine.endPoint.Y - aLine.startPoint.Y);
double s = Math.Sqrt(dis);
e.Graphics.DrawEllipse(Pens.Green, aLine.startPoint.X, aLine.startPoint.Y, Convert.ToInt16(s), Convert.ToInt16(s));
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
l = new circle();
l.startPoint = e.Location;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
Cursor.Current = Cursors.Cross;
//collect endPoint when mouse moved
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
l.endPoint = e.Location;
//Line completed
allcircle.Add(l);
this.pictureBox1.Invalidate();
}
}
}
how to find mid point in this to draw a radius