how to draw circle wit radius in .net winfoms

Posted by Shanky11 under Windows Forms on 10/3/2013 | Points: 10 | Views : 1807 | Status : [Member] | Replies : 2
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
this.pictureBox1.Invalidate();

}
}

}
how to find mid point in this to draw a radius

Responses

Posted by: Bandi on: 10/3/2013 [Member] [MVP] Platinum | Points: 25