你好
我想在一个大椭圆上画 40 个椭圆。真奇怪。
for (int i = 0; i < 40; i++)
{
{
{
Random r = new Random();
int distance = r.Next(0, 10000);
var rv = r.Next(0, 359);
var x = Math.Sin(rv * Math.PI / 180) * 225;
rv = r.Next(0, 359);
var y = Math.Cos(rv * Math.PI / 180) * 225;
Ellipse e = new Ellipse();
e.Fill = new SolidColorBrush(Color.FromArgb(255, (byte)(counter * 5), (byte)(counter * 3), (byte)(counter * 1)));
e.Margin = new Thickness(y, -150 + x, 0, 0);
e.Width = 25;
e.Height = 25;
counter++;
PointsGrid.Children.Add(e);
}
}
}
此代码仅绘制 7,8 或有时 9 个椭圆。但是,如果我在代码中添加额外的行:
for (int i = 0; i < 40; i++)
{
{
{
Random r = new Random();
int distance = r.Next(0, 10000);
var rv = r.Next(0, 359);
var x = Math.Sin(rv * Math.PI / 180) * 225;
rv = r.Next(0, 359);
var y = Math.Cos(rv * Math.PI / 180) * 225;
Ellipse e = new Ellipse();
e.Fill = new SolidColorBrush(Color.FromArgb(255, (byte)(counter * 5), (byte)(counter * 3), (byte)(counter * 1)));
e.Margin = new Thickness(y, -150 + x, 0, 0);
e.Width = 25;
e.Height = 25;
counter++;
PointsGrid.Children.Add(e);
MessageBox.Show(""); // Additional line
}
}
}
如果我添加显示消息框,在所有消息框上按确定,我将看到所有 40 个省略号...
问题是它怎么可能,我该如何解决?