我需要在面板中绘制10000点而不会阻止UI。我正在使用C#。目前,我正在面板涂料活动中进行绘图。我该怎么做,而无需阻止UI。我已经尝试在单独的线程上进行"绘画",但未能成功
private void Panel1Paint(object sender, PaintEventArgs paintEventArgs)
{
var g = paintEventArgs.Graphics;
g.DrawLine(new Pen(Color.Black),
new Point(0, panel1.Width / 2),
new Point(panel1.Height, panel1.Width / 2));
g.DrawLine(new Pen(Color.Black),
new Point(panel1.Width / 2, 0),
new Point(panel1.Width / 2, panel1.Height));
for (int i = 0; i < centres.Length; i++)
{
g.FillEllipse(new SolidBrush(colors[i]), centres[i].X, centres[i].Y, 10, 10);
Console.Out.WriteLine(centres[i].ToCart());
}
for (int i = 0; i < 10000; i++)
{
int zona = r.Next(0, 3);
double p_gauss, p_rand;
int new_x;
int new_y;
do
{
new_x = r.Next(0, 400);
p_gauss = Gauss(new_x, centres[zona].X, s[zona].X);
p_rand = r.NextDouble();
} while (p_gauss < p_rand);
do
{
new_y = r.Next(0, 400);
p_gauss = Gauss(new_y, centres[zona].Y, s[zona].Y);
p_rand = r.NextDouble();
} while (p_gauss < p_rand);
g.DrawEllipse(new Pen(colors[zona], 2), new_x, new_y, 1, 1);
}
}
在线程中在位图上进行绘画。使成品位图可用于您的表格,并让油漆事件一次绘制整个位图。