gpt4 book ai didi

c# - 为什么画圈后颜色会变?

转载 作者:太空狗 更新时间:2023-10-30 01:32:07 24 4
gpt4 key购买 nike

为什么画圈后颜色会变? ,事实上,我画了圆圈,但我的问题是每次双击后,下一个圆圈的颜色从蓝色变为背景色。

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();
}
}

enter image description here

最佳答案

您正确绘制了椭圆,但您总是只填充其中一个(最后添加的一个,在光标位置)。

// 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);

关于c# - 为什么画圈后颜色会变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38331633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com