事实上,我想每次双击并且不需要删除前的圆圈,就可以在新的位置绘制圆圈。需要注意的是,我使用了PictureBox
。在不移除前一个圈的情况下在新位置绘制圆圈?
public Point postionCursor { get; set; }
List<Point> points = new List<Point>();
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
postionCursor = this.PointToClient(new Point(Cursor.Position.X - 25, Cursor.Position.Y - 25));
points.Add(postionCursor);
pictureBox1.Invalidate();
pictureBox1.Paint += new PaintEventHandler(pic_Paint);
}
private void pic_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
foreach (Point pt in points)
{
Pen p = new Pen(Color.Tomato, 2);
SolidBrush myb = new SolidBrush(Color.White);
g.DrawEllipse(p, postionCursor.X, postionCursor.Y, 20, 20);
g.FillEllipse(myb, postionCursor.X, postionCursor.Y, 20, 20);
p.Dispose();
}
}
然后在paint事件中绘制〜before〜circle。 – Ralf
'pictureBox1.Paint + = new PaintEventHandler(pic_Paint);'应该在你的表单加载或构造函数中。 –
@ RezaAghaei,为什么只能在构造函数中使用?多解释一下? –