Reputation: 556
I am trying to draw an ellipse according to mouse points(starting and ending point) using the following code...
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
start = new Point(e.X, e.Y);
// Point mouseDownLocation = pictureBox1.PointToClient(new Point(e.X, e.Y))
mRect = new Rectangle(e.X, e.Y, 0, 0);
}
and
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
end = new Point(e.X, e.Y);
pictureBox1.Invalidate();
if (listRect.Count <= 4)
{
listRect.Add(mRect);
this.getObjectPopup(e);
}
else
{
MessageBox.Show("Maximum 5 selection per Image", "Alert", MessageBoxButtons.OK);
}
}
and on paint event wrote the following code
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Color c1 = Color.FromArgb(50, Color.Green);
foreach (Rectangle rect in listRect)
{
using (Pen pen = new Pen(Color.Red, 2))
{
float angle = (float)Angle(start, end);
Matrix transformMatrix = new Matrix();
transformMatrix.Translate(200.0F, 0.0F);
e.Graphics.RotateTransform(angle);
// e.Graphics.MultiplyTransform(transformMatrix, MatrixOrder.Append);
e.Graphics.DrawEllipse(pen, rect.X, rect.Y, rect.Width, rect.Height);
e.Graphics.FillEllipse(new SolidBrush(c1), rect.X, rect.Y, rect.Width, rect.Height);
this.WriteText(e,rect);
}
}
}
ellipse has been drawn but not along with mouse starting and ending points
Upvotes: 1
Views: 1858
Reputation: 777
Have you tried to set horizontal and vertical alignment?
rect.HorizontalAlignment = HorizontalAlignment.Left;
rect.VerticalAlignment = VerticalAlignment.Top;
EDIT: respectively setting those properties on the Ellipse
Upvotes: 1