事實上,我想每次雙擊並且不需要刪除前的圓圈,就可以在新的位置繪製圓圈。需要注意的是,我使用了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,爲什麼只能在構造函數中使用?多解釋一下? –