用的C#,想在picturebox中隔1秒显示一段直线,前面画的直线都保留,该怎么写?
注:我只能把线一起显示出来,不能让它分开显示。
------解决方案--------------------------------------------------------
处理onpaint事件,有需要花的线保存在数组总每次遍历,数组越来越大,线条越来越多
注:我只能把线一起显示出来,不能让它分开显示。
处理数组长度,也就是控制每次画线的条数
------解决方案--------------------------------------------------------
- C# code
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Random random = new Random(); Func<int[]> getPoints = new Func<int[]>(() => { return new int[] { random.Next(500), random.Next(500) }; }); Action work = new Action(() => { while (true) { using ( Pen skyBluePen = new Pen(Color.Red)) { int[] point = getPoints(); this.CreateGraphics().DrawLine(skyBluePen, point[0], point[0], point[1], point[1]); Thread.Sleep(1000); } } }); Thread th = new Thread(new ThreadStart(work)); th.Start(); }