Bitmap bp = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(bp);
g.Clear(Color.White);
for (int i = 0; i < 25; i++)
{
Random r = new Random();
int r1 = r.Next(bp.Width);
int r2 = r.Next(bp.Width);
int h1 = r.Next(bp.Height);
int h2 = r.Next(bp.Height);
Pen p = new Pen(Color.Silver);
g.DrawLine(p, r1, h1, r2, h2);
}
pictureBox1.Image = (Image)bp;
循环只执行了一次,断点时 或在循环中加入Thread.Sleep(10)方法可完全执行