为什么画圈后它们的颜色会发生变化?事实上,我画圆圈但我的问题是,每次双击后,下一个圆圈的颜色会从蓝色变为背景颜色。
public Form1()
{
InitializeComponent();
pictureBox1.Paint += new PaintEventHandler(pic_Paint);
}
public Point positionCursor { get; set; }
private List<Point> points = new List<Point>();
public int circleNumber { get; set; }
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
positionCursor = this.PointToClient(new Point(Cursor.Position.X - 25, Cursor.Position.Y - 25));
points.Add(positionCursor);
pictureBox1.Invalidate();
}
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);
g.FillEllipse(Brushes.Blue, positionCursor.X, positionCursor.Y, 20, 20);
g.DrawEllipse(p, pt.X, pt.Y, 20, 20);
p.Dispose();
}
}
答案 0 :(得分:3)
您正确地绘制了省略号,但是您始终只填充其中一个(最后一个添加,位于光标的位置)。
// This is ok
g.DrawEllipse(p, pt.X, pt.Y, 20, 20);
// You should use pt.X and pt.Y here
g.FillEllipse(Brushes.Blue, positionCursor.X, positionCursor.Y, 20, 20);
答案 1 :(得分:0)
将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);
g.DrawEllipse(p, pt.X, pt.Y, 20, 20);
g.FillEllipse(Brushes.Blue, pt.X, pt.Y, 20, 20);
p.Dispose();
}
}